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

View File

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

View File

@ -9,33 +9,39 @@ var Steppy = require('twostep').Steppy,
function Distributor(params) { function Distributor(params) {
var self = this; this.nodes = params.nodes;
// nodes to execute builds
self.nodes = _(params.nodes).map(function(nodeParams) {
return self._createNode(nodeParams);
});
// queued projects to build
self.queue = [];
self.saveBuild = params.saveBuild || function(build, callback) { // queued projects to build
this.queue = [];
this.saveBuild = params.saveBuild || function(build, callback) {
callback(null, build); callback(null, build);
}; };
self.removeBuild = params.removeBuild || function(build, callback) { this.removeBuild = params.removeBuild || function(build, callback) {
callback(); callback();
}; };
self.projects = params.projects; this.projects = params.projects;
self.notifier = params.notifier; this.notifier = params.notifier;
self.buildLogLineNumbersHash = {}, this.buildLogLineNumbersHash = {},
self.lastLinesHash = {}; this.lastLinesHash = {};
} }
inherits(Distributor, EventEmitter); inherits(Distributor, EventEmitter);
exports.Distributor = Distributor; 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) { Distributor.prototype._createNode = function(params) {
return createNode(params); return createNode(params);
}; };

View File

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