mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-02-11 06:49:15 +00:00
change exposed notifier api
This commit is contained in:
parent
a7f03343ac
commit
918a42fff5
6
app.js
6
app.js
@ -9,12 +9,11 @@ var env = process.env.NODE_ENV || 'development',
|
|||||||
_ = require('underscore'),
|
_ = require('underscore'),
|
||||||
Reader = require('./lib/reader').Reader,
|
Reader = require('./lib/reader').Reader,
|
||||||
Notifier = require('./lib/notifier').Notifier,
|
Notifier = require('./lib/notifier').Notifier,
|
||||||
BaseNotifierTransport = require('./lib/notifier/transport/base').Transport,
|
|
||||||
ConsoleNotifierTransport = require('./lib/notifier/transport/console').Transport,
|
|
||||||
ProjectsCollection = require('./lib/project').ProjectsCollection,
|
ProjectsCollection = require('./lib/project').ProjectsCollection,
|
||||||
BuildsCollection = require('./lib/build').BuildsCollection,
|
BuildsCollection = require('./lib/build').BuildsCollection,
|
||||||
libLogger = require('./lib/logger'),
|
libLogger = require('./lib/logger'),
|
||||||
libReader = require('./lib/reader'),
|
libReader = require('./lib/reader'),
|
||||||
|
libNotifier = require('./lib/notifier'),
|
||||||
libNode = require('./lib/node'),
|
libNode = require('./lib/node'),
|
||||||
libCommand = require('./lib/command'),
|
libCommand = require('./lib/command'),
|
||||||
libExecutor = require('./lib/executor'),
|
libExecutor = require('./lib/executor'),
|
||||||
@ -63,9 +62,9 @@ app.httpServer.addRequestListener(function(req, res, next) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.lib = {};
|
app.lib = {};
|
||||||
app.lib.BaseNotifierTransport = BaseNotifierTransport;
|
|
||||||
app.lib.logger = libLogger;
|
app.lib.logger = libLogger;
|
||||||
app.lib.reader = libReader;
|
app.lib.reader = libReader;
|
||||||
|
app.lib.notifier = libNotifier;
|
||||||
app.lib.command = libCommand;
|
app.lib.command = libCommand;
|
||||||
app.lib.executor = libExecutor;
|
app.lib.executor = libExecutor;
|
||||||
app.lib.scm = libScm;
|
app.lib.scm = libScm;
|
||||||
@ -223,7 +222,6 @@ Steppy(
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.notifier = new Notifier({db: db});
|
app.notifier = new Notifier({db: db});
|
||||||
app.notifier.register('console', ConsoleNotifierTransport);
|
|
||||||
|
|
||||||
completeUncompletedBuilds(this.slot());
|
completeUncompletedBuilds(this.slot());
|
||||||
},
|
},
|
||||||
|
@ -2,29 +2,36 @@
|
|||||||
|
|
||||||
var Steppy = require('twostep').Steppy,
|
var Steppy = require('twostep').Steppy,
|
||||||
_ = require('underscore'),
|
_ = require('underscore'),
|
||||||
logger = require('../logger')('notifier');
|
logger = require('../logger')('notifier'),
|
||||||
|
BaseNotifierTransport = require('./transport/base').Transport,
|
||||||
|
ConsoleNotifierTransport = require('./transport/console').Transport;
|
||||||
|
|
||||||
|
var constructors = {
|
||||||
|
console: ConsoleNotifierTransport
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.register = function(type, constructor) {
|
||||||
|
constructors[type] = constructor;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.BaseNotifierTransport = BaseNotifierTransport;
|
||||||
|
|
||||||
|
|
||||||
function Notifier(params) {
|
function Notifier(params) {
|
||||||
this.db = params.db;
|
this.db = params.db;
|
||||||
|
|
||||||
this.constructors = {};
|
|
||||||
this.instances = {};
|
this.instances = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.Notifier = Notifier;
|
exports.Notifier = Notifier;
|
||||||
|
|
||||||
Notifier.prototype.register = function(type, constructor) {
|
|
||||||
this.constructors[type] = constructor;
|
|
||||||
};
|
|
||||||
|
|
||||||
Notifier.prototype.init = function(params, callback) {
|
Notifier.prototype.init = function(params, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
Steppy(
|
Steppy(
|
||||||
function() {
|
function() {
|
||||||
var initGroup = this.makeGroup();
|
var initGroup = this.makeGroup();
|
||||||
_(self.constructors).each(function(Constructor, type) {
|
_(constructors).each(function(Constructor, type) {
|
||||||
self.instances[type] = new Constructor();
|
self.instances[type] = new Constructor();
|
||||||
self.instances[type].init(params[type], initGroup.slot());
|
self.instances[type].init(params[type], initGroup.slot());
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var Notifier = require('../lib/notifier').Notifier,
|
var libNotifier = require('../lib/notifier'),
|
||||||
|
Notifier = libNotifier.Notifier,
|
||||||
expect = require('expect.js'),
|
expect = require('expect.js'),
|
||||||
sinon = require('sinon'),
|
sinon = require('sinon'),
|
||||||
_ = require('underscore');
|
_ = require('underscore');
|
||||||
@ -19,7 +20,7 @@ describe('notifier module', function() {
|
|||||||
|
|
||||||
describe('test notifier', function() {
|
describe('test notifier', function() {
|
||||||
it('should be rigestered', function() {
|
it('should be rigestered', function() {
|
||||||
notifier.register('test', TestTransport);
|
libNotifier.register('test', TestTransport);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be intialized without errors', function(done) {
|
it('should be intialized without errors', function(done) {
|
||||||
|
Loading…
Reference in New Issue
Block a user