mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-01-11 05:55:07 +00:00
41 lines
1019 B
JavaScript
41 lines
1019 B
JavaScript
'use strict';
|
|
|
|
var _ = require('underscore'),
|
|
logger = require('./lib/logger')('scheduler'),
|
|
CronJob = require('cron').CronJob;
|
|
|
|
exports.init = function(app, callback) {
|
|
|
|
var distributor = app.distributor,
|
|
projectJobs = {};
|
|
|
|
app.on('projectLoaded', function(project) {
|
|
var time = project.buildEvery && project.buildEvery.time;
|
|
if (time) {
|
|
logger.log('Start job for loaded project "%s"', project.name);
|
|
projectJobs[project.name] = {};
|
|
projectJobs[project.name].job = new CronJob({
|
|
cronTime: time,
|
|
onTick: function() {
|
|
logger.log('Run project "%s"', project.name);
|
|
distributor.run({
|
|
projectName: project.name,
|
|
withScmChangesOnly: project.buildEvery.withScmChangesOnly
|
|
});
|
|
},
|
|
start: true
|
|
});
|
|
}
|
|
});
|
|
|
|
app.on('projectUnloaded', function(project) {
|
|
if (project.name in projectJobs) {
|
|
logger.log('Stop job for unloaded project "%s"', project.name);
|
|
projectJobs[project.name].job.stop();
|
|
delete projectJobs[project.name];
|
|
}
|
|
});
|
|
|
|
callback();
|
|
};
|