create distributor node after plugins load

This commit is contained in:
oleg 2016-03-01 00:11:58 +03:00
parent 4304cd009e
commit 1bf07741ab
4 changed files with 24 additions and 15 deletions

4
app.js
View File

@ -230,7 +230,7 @@ Steppy(
completeUncompletedBuilds(this.slot());
},
function() {
require('./distributor').init(app, this.slot());
require('./distributor').create(app, this.slot());
},
function(err, distributor) {
app.builds = new BuildsCollection({
@ -244,6 +244,8 @@ Steppy(
require(plugin).register(app);
});
distributor.init();
app.notifier.init(app.config.notify, this.slot());
},
function() {

View File

@ -7,7 +7,7 @@ var Steppy = require('twostep').Steppy,
logger = require('./lib/logger')('distributor');
exports.init = function(app, callback) {
exports.create = function(app, callback) {
var distributor = new Distributor({
nodes: app.config.nodes,
projects: app.projects,

View File

@ -9,33 +9,39 @@ var Steppy = require('twostep').Steppy,
function Distributor(params) {
var self = this;
// nodes to execute builds
self.nodes = _(params.nodes).map(function(nodeParams) {
return self._createNode(nodeParams);
});
// queued projects to build
self.queue = [];
this.nodes = params.nodes;
self.saveBuild = params.saveBuild || function(build, callback) {
// queued projects to build
this.queue = [];
this.saveBuild = params.saveBuild || function(build, callback) {
callback(null, build);
};
self.removeBuild = params.removeBuild || function(build, callback) {
this.removeBuild = params.removeBuild || function(build, callback) {
callback();
};
self.projects = params.projects;
self.notifier = params.notifier;
this.projects = params.projects;
this.notifier = params.notifier;
self.buildLogLineNumbersHash = {},
self.lastLinesHash = {};
this.buildLogLineNumbersHash = {},
this.lastLinesHash = {};
}
inherits(Distributor, EventEmitter);
exports.Distributor = Distributor;
// do deferred initialization (e.g. create nodes after all plugins load)
Distributor.prototype.init = function() {
var self = this;
// nodes to execute builds
self.nodes = _(self.nodes).map(function(nodeParams) {
return self._createNode(nodeParams);
});
};
Distributor.prototype._createNode = function(params) {
return createNode(params);
};

View File

@ -52,6 +52,7 @@ exports.createDistributor = function(params) {
});
var distributor = new Distributor(distributorParams);
distributor.init();
if (mockNode) {
Distributor.prototype._createNode.restore();