local to base node, add register, create functions
This commit is contained in:
parent
baceedd70e
commit
2a7d6dfb98
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
var Steppy = require('twostep').Steppy,
|
var Steppy = require('twostep').Steppy,
|
||||||
_ = require('underscore'),
|
_ = require('underscore'),
|
||||||
Node = require('./node').Node,
|
createNode = require('./node').createNode,
|
||||||
EventEmitter = require('events').EventEmitter,
|
EventEmitter = require('events').EventEmitter,
|
||||||
inherits = require('util').inherits,
|
inherits = require('util').inherits,
|
||||||
logger = require('./logger')('distributor');
|
logger = require('./logger')('distributor');
|
||||||
@ -36,8 +36,8 @@ inherits(Distributor, EventEmitter);
|
|||||||
|
|
||||||
exports.Distributor = Distributor;
|
exports.Distributor = Distributor;
|
||||||
|
|
||||||
Distributor.prototype._createNode = function(nodeParams) {
|
Distributor.prototype._createNode = function(params) {
|
||||||
return new Node(nodeParams);
|
return createNode(params);
|
||||||
};
|
};
|
||||||
|
|
||||||
Distributor.prototype._runNext = function(callback) {
|
Distributor.prototype._runNext = function(callback) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var _ = require('underscore'),
|
var _ = require('underscore');
|
||||||
createExecutor = require('./executor').createExecutor;
|
|
||||||
|
|
||||||
|
|
||||||
function Node(params) {
|
function Node(params) {
|
||||||
@ -76,13 +75,6 @@ Node.prototype.getFreeExecutorsCount = function() {
|
|||||||
return this.maxExecutorsCount - _(this.executors).size();
|
return this.maxExecutorsCount - _(this.executors).size();
|
||||||
};
|
};
|
||||||
|
|
||||||
Node.prototype._createExecutor = function(project) {
|
|
||||||
return createExecutor({
|
|
||||||
type: this.type,
|
|
||||||
project: project
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Node.prototype.hasScmChanges = function(project, callback) {
|
Node.prototype.hasScmChanges = function(project, callback) {
|
||||||
this._createExecutor(project).hasScmChanges(callback);
|
this._createExecutor(project).hasScmChanges(callback);
|
||||||
};
|
};
|
18
lib/node/index.js
Normal file
18
lib/node/index.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var constructors = {
|
||||||
|
local: require('./local').Node
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.register = function(type, constructor) {
|
||||||
|
constructor[type] = constructor;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.createNode = function(params) {
|
||||||
|
if (params.type in constructors === false) {
|
||||||
|
throw new Error('Unknown node type: ', params.type);
|
||||||
|
}
|
||||||
|
|
||||||
|
var Constructor = constructors[params.type];
|
||||||
|
return new Constructor(params);
|
||||||
|
};
|
20
lib/node/local.js
Normal file
20
lib/node/local.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
'user strict';
|
||||||
|
|
||||||
|
var inherits = require('util').inherits,
|
||||||
|
ParentNode = require('./base').Node,
|
||||||
|
LocalExecutor = require('../executor/local').Executor;
|
||||||
|
|
||||||
|
function Node(params) {
|
||||||
|
ParentNode.call(this, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
inherits(Node, ParentNode);
|
||||||
|
|
||||||
|
exports.Node = Node;
|
||||||
|
|
||||||
|
Node.prototype._createExecutor = function(project) {
|
||||||
|
return new LocalExecutor({
|
||||||
|
type: this.type,
|
||||||
|
project: project
|
||||||
|
});
|
||||||
|
};
|
@ -2,16 +2,16 @@
|
|||||||
|
|
||||||
var _ = require('underscore'),
|
var _ = require('underscore'),
|
||||||
sinon = require('sinon'),
|
sinon = require('sinon'),
|
||||||
Node = require('../../lib/node').Node,
|
createNode = require('../../lib/node').createNode,
|
||||||
EventEmitter = require('events').EventEmitter,
|
EventEmitter = require('events').EventEmitter,
|
||||||
ProjectsCollection = require('../../lib/project').ProjectsCollection,
|
ProjectsCollection = require('../../lib/project').ProjectsCollection,
|
||||||
Distributor = require('../../lib/distributor').Distributor,
|
Distributor = require('../../lib/distributor').Distributor,
|
||||||
Notifier = require('../../lib/notifier').Notifier;
|
Notifier = require('../../lib/notifier').Notifier;
|
||||||
|
|
||||||
|
|
||||||
var createNode = function(executorRun) {
|
var createMockedNode = function(executorRun) {
|
||||||
return function(params) {
|
return function(params) {
|
||||||
var node = new Node(params);
|
var node = createNode(params);
|
||||||
node._createExecutor = function(project) {
|
node._createExecutor = function(project) {
|
||||||
var executor = new EventEmitter();
|
var executor = new EventEmitter();
|
||||||
executor.project = project;
|
executor.project = project;
|
||||||
@ -38,7 +38,7 @@ exports.createDistributor = function(params) {
|
|||||||
distributorParams.executorRun || sinon.stub().callsArgAsync(1)
|
distributorParams.executorRun || sinon.stub().callsArgAsync(1)
|
||||||
);
|
);
|
||||||
// patch method which will be called at constructor
|
// patch method which will be called at constructor
|
||||||
sinon.stub(Distributor.prototype, '_createNode', createNode(
|
sinon.stub(Distributor.prototype, '_createNode', createMockedNode(
|
||||||
executorRun
|
executorRun
|
||||||
));
|
));
|
||||||
delete distributorParams.executorRun;
|
delete distributorParams.executorRun;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var Node = require('../lib/node').Node,
|
var createNode = require('../lib/node').createNode,
|
||||||
expect = require('expect.js');
|
expect = require('expect.js');
|
||||||
|
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ describe('Node', function() {
|
|||||||
|
|
||||||
describe('basic', function() {
|
describe('basic', function() {
|
||||||
it('instance should be created without errors', function() {
|
it('instance should be created without errors', function() {
|
||||||
node = new Node({
|
node = createNode({
|
||||||
type: 'local',
|
type: 'local',
|
||||||
maxExecutorsCount: 1
|
maxExecutorsCount: 1
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user