add scheduler

This commit is contained in:
oleg 2015-07-12 11:39:22 +03:00
parent 72a1d40bf9
commit dc915432a6
5 changed files with 63 additions and 11 deletions

View File

@ -19,7 +19,7 @@ work in progress...
* Work with git
* ~~Build every commit, commit with tag, etc~~
* ~~Safe id and build numbers generation~~
* Scheduler
* ~~Scheduler~~
* ~~Better tests coverage~~
* Semantic versioning and plugins

10
app.js
View File

@ -100,9 +100,6 @@ Steppy(
function(err, projects) {
// note that `app.projects` is live variable
app.projects = projects;
_(app.projects).each(function(project) {
app.emit('projectLoaded', project);
});
logger.log('Loaded projects: ', _(app.projects).pluck('name'));
require('./distributor').init(app, this.slot());
@ -122,6 +119,13 @@ Steppy(
require('./projectsWatcher').init(app, this.slot());
require('./scheduler').init(app, this.slot());
// notify about first project loading
_(app.projects).each(function(project) {
app.emit('projectLoaded', project);
});
// init resources
require('./resources')(app);
},

View File

@ -7,6 +7,10 @@ scm:
catchRev:
comment: !!js/regexp //
# buildEvery:
# time: "*/5 * * * * *"
# withScmChangesOnly: true
notify:
on:
# - done

View File

@ -21,13 +21,16 @@
"ci",
"build"
],
"contributors": [{
"name": "Oleg Korobenko",
"email": "oleg.korobenko@gmail.com"
}, {
"name": "Vladimir Polyakov",
"email": "nrd11k@gmail.com"
}],
"contributors": [
{
"name": "Oleg Korobenko",
"email": "oleg.korobenko@gmail.com"
},
{
"name": "Vladimir Polyakov",
"email": "nrd11k@gmail.com"
}
],
"license": "MIT",
"bugs": {
"url": "https://github.com/okv/nci/issues"
@ -36,6 +39,7 @@
"dependencies": {
"chokidar": "1.0.3",
"colors": "1.1.2",
"cron": "1.0.9",
"data.io": "0.3.0",
"jade": "1.9.2",
"nlevel": "1.0.2",

40
scheduler.js Normal file
View File

@ -0,0 +1,40 @@
'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();
};