diff --git a/data/config.yaml b/data/config.yaml index 88837b5..b4af7d2 100644 --- a/data/config.yaml +++ b/data/config.yaml @@ -1,6 +1,6 @@ nodes: - type: local - maxExecutorsCount: 1 + maxExecutorsCount: 2 notify: {} diff --git a/lib/distributor.js b/lib/distributor.js index a341019..104a242 100644 --- a/lib/distributor.js +++ b/lib/distributor.js @@ -59,7 +59,7 @@ Distributor.prototype._runNext = function(callback) { self._updateBuild( queueItem.build, - {startDate: Date.now(), status: 'in-progress'}, + {startDate: Date.now(), status: 'in-progress', waitReason: ''}, this.slot() ); }, @@ -75,7 +75,13 @@ Distributor.prototype._runNext = function(callback) { error: err ? err.message : null }, function(err, build) { - self._onBuildComplete(err, build, stepCallback) + if (err) { + console.error( + 'Error during build update: ', err.stack || err + ); + return stepCallback(err); + } + self._onBuildComplete(build, stepCallback); } ); }); @@ -107,13 +113,14 @@ Distributor.prototype._updateWaitReasons = function() { }); var waitReason = _(waitReasons).compact().join(', '); - if (waitReason !== item.build.waitReason) { + // set only non-empty reasons + if (waitReason && waitReason !== item.build.waitReason) { self._updateBuild(item.build, {waitReason: waitReason}); } }); }; -Distributor.prototype._onBuildComplete = function(err, build, callback) { +Distributor.prototype._onBuildComplete = function(build, callback) { var self = this; Steppy( diff --git a/lib/node.js b/lib/node.js index 337b811..aafdc21 100644 --- a/lib/node.js +++ b/lib/node.js @@ -28,6 +28,10 @@ Node.prototype.hasFreeExecutor = function(project) { return !this.getExecutorWaitReason(project); }; +Node.prototype.getFreeExecutorsCount = function() { + return this.maxExecutorsCount - _(this.executors).size(); +}; + Node.prototype._createExecutor = function(project) { return createExecutor({ type: this.type, diff --git a/test/distributor.js b/test/distributor.js index 3e7fe89..2fc6d30 100644 --- a/test/distributor.js +++ b/test/distributor.js @@ -69,20 +69,15 @@ describe('Distributor', function() { expect(changes.completed).equal(false); }); - it('build should have empty wait reason', function() { + it('build should be in-progress', function() { var changes = updateBuildSpy.getCall(1).args[1]; - expect(changes).only.have.keys('waitReason'); + expect(changes).only.have.keys('startDate', 'status', 'waitReason'); + expect(changes.status).equal('in-progress'); expect(changes.waitReason).equal(''); }); - it('build should be in-progress', function() { - var changes = updateBuildSpy.getCall(2).args[1]; - expect(changes).only.have.keys('startDate', 'status'); - expect(changes.status).equal('in-progress'); - }); - it('build should be done', function() { - var changes = updateBuildSpy.getCall(3).args[1]; + var changes = updateBuildSpy.getCall(2).args[1]; expect(changes).only.have.keys( 'endDate', 'status', 'completed', 'error' ); @@ -91,8 +86,8 @@ describe('Distributor', function() { expect(changes.error).equal(null); }); - it('update build called 4 times in total', function() { - expect(updateBuildSpy.callCount).equal(4); + it('update build called 3 times in total', function() { + expect(updateBuildSpy.callCount).equal(3); }); after(function() { @@ -134,26 +129,20 @@ describe('Distributor', function() { expect(changes.status).equal('queued'); }); - it('build should have empty wait reason', function() { - var changes = updateBuildSpy.getCall(1).args[1]; - expect(changes).only.have.keys('waitReason'); - expect(changes.waitReason).equal(''); - }); - it('build should be in-progress', function() { - var changes = updateBuildSpy.getCall(2).args[1]; + var changes = updateBuildSpy.getCall(1).args[1]; expect(changes.status).equal('in-progress'); }); it('build should be fail', function() { - var changes = updateBuildSpy.getCall(3).args[1]; + var changes = updateBuildSpy.getCall(2).args[1]; expect(changes.status).equal('error'); expect(changes.completed).equal(true); expect(changes.error).equal('Some error'); }); - it('update build called 4 times in total', function() { - expect(updateBuildSpy.callCount).equal(4); + it('update build called 3 times in total', function() { + expect(updateBuildSpy.callCount).equal(3); }); after(function() {