add scheduler
This commit is contained in:
parent
72a1d40bf9
commit
dc915432a6
@ -19,7 +19,7 @@ work in progress...
|
|||||||
* Work with git
|
* Work with git
|
||||||
* ~~Build every commit, commit with tag, etc~~
|
* ~~Build every commit, commit with tag, etc~~
|
||||||
* ~~Safe id and build numbers generation~~
|
* ~~Safe id and build numbers generation~~
|
||||||
* Scheduler
|
* ~~Scheduler~~
|
||||||
* ~~Better tests coverage~~
|
* ~~Better tests coverage~~
|
||||||
* Semantic versioning and plugins
|
* Semantic versioning and plugins
|
||||||
|
|
||||||
|
10
app.js
10
app.js
@ -100,9 +100,6 @@ Steppy(
|
|||||||
function(err, projects) {
|
function(err, projects) {
|
||||||
// note that `app.projects` is live variable
|
// note that `app.projects` is live variable
|
||||||
app.projects = projects;
|
app.projects = projects;
|
||||||
_(app.projects).each(function(project) {
|
|
||||||
app.emit('projectLoaded', project);
|
|
||||||
});
|
|
||||||
logger.log('Loaded projects: ', _(app.projects).pluck('name'));
|
logger.log('Loaded projects: ', _(app.projects).pluck('name'));
|
||||||
|
|
||||||
require('./distributor').init(app, this.slot());
|
require('./distributor').init(app, this.slot());
|
||||||
@ -122,6 +119,13 @@ Steppy(
|
|||||||
|
|
||||||
require('./projectsWatcher').init(app, this.slot());
|
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
|
// init resources
|
||||||
require('./resources')(app);
|
require('./resources')(app);
|
||||||
},
|
},
|
||||||
|
@ -7,6 +7,10 @@ scm:
|
|||||||
catchRev:
|
catchRev:
|
||||||
comment: !!js/regexp //
|
comment: !!js/regexp //
|
||||||
|
|
||||||
|
# buildEvery:
|
||||||
|
# time: "*/5 * * * * *"
|
||||||
|
# withScmChangesOnly: true
|
||||||
|
|
||||||
notify:
|
notify:
|
||||||
on:
|
on:
|
||||||
# - done
|
# - done
|
||||||
|
18
package.json
18
package.json
@ -21,13 +21,16 @@
|
|||||||
"ci",
|
"ci",
|
||||||
"build"
|
"build"
|
||||||
],
|
],
|
||||||
"contributors": [{
|
"contributors": [
|
||||||
"name": "Oleg Korobenko",
|
{
|
||||||
"email": "oleg.korobenko@gmail.com"
|
"name": "Oleg Korobenko",
|
||||||
}, {
|
"email": "oleg.korobenko@gmail.com"
|
||||||
"name": "Vladimir Polyakov",
|
},
|
||||||
"email": "nrd11k@gmail.com"
|
{
|
||||||
}],
|
"name": "Vladimir Polyakov",
|
||||||
|
"email": "nrd11k@gmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/okv/nci/issues"
|
"url": "https://github.com/okv/nci/issues"
|
||||||
@ -36,6 +39,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chokidar": "1.0.3",
|
"chokidar": "1.0.3",
|
||||||
"colors": "1.1.2",
|
"colors": "1.1.2",
|
||||||
|
"cron": "1.0.9",
|
||||||
"data.io": "0.3.0",
|
"data.io": "0.3.0",
|
||||||
"jade": "1.9.2",
|
"jade": "1.9.2",
|
||||||
"nlevel": "1.0.2",
|
"nlevel": "1.0.2",
|
||||||
|
40
scheduler.js
Normal file
40
scheduler.js
Normal 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();
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user