From 1bf07741abf2741e9877cbf418701474f23d485d Mon Sep 17 00:00:00 2001 From: oleg Date: Tue, 1 Mar 2016 00:11:58 +0300 Subject: [PATCH] create distributor node after plugins load --- app.js | 4 +++- distributor.js | 2 +- lib/distributor.js | 32 +++++++++++++++++++------------- test/distributor/helpers.js | 1 + 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/app.js b/app.js index cdca103..250547b 100644 --- a/app.js +++ b/app.js @@ -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() { diff --git a/distributor.js b/distributor.js index e7e4a75..f523c68 100644 --- a/distributor.js +++ b/distributor.js @@ -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, diff --git a/lib/distributor.js b/lib/distributor.js index 7bc7b92..f35e21a 100644 --- a/lib/distributor.js +++ b/lib/distributor.js @@ -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); }; diff --git a/test/distributor/helpers.js b/test/distributor/helpers.js index 3fcc3be..a66da3b 100644 --- a/test/distributor/helpers.js +++ b/test/distributor/helpers.js @@ -52,6 +52,7 @@ exports.createDistributor = function(params) { }); var distributor = new Distributor(distributorParams); + distributor.init(); if (mockNode) { Distributor.prototype._createNode.restore();