nci/distributor.js

61 lines
1.3 KiB
JavaScript
Raw Normal View History

'use strict';
var Steppy = require('twostep').Steppy,
_ = require('underscore'),
Distributor = require('./lib/distributor').Distributor,
db = require('./db'),
2015-10-04 16:57:53 +00:00
logger = require('./lib/logger')('distributor');
exports.init = function(app, callback) {
var distributor = new Distributor({
nodes: app.config.nodes,
projects: app.projects,
saveBuild: function(build, callback) {
Steppy(
function() {
2015-11-19 17:28:51 +00:00
if (_(build.project).has('avgBuildDuration')) {
this.pass(build.project.avgBuildDuration);
2015-11-19 17:28:51 +00:00
} else {
app.builds.getProjectAvgBuildDuration({
projectName: build.project.name
}, this.slot());
}
},
function(err, avgBuildDuration) {
build.project.avgBuildDuration = avgBuildDuration;
db.builds.put(build, this.slot());
},
function() {
this.pass(build);
},
callback
);
},
removeBuild: function(build, callback) {
Steppy(
function() {
db.builds.del([build.id], this.slot());
},
callback
);
}
});
distributor.on('buildLogLines', function(build, lines) {
2015-11-19 17:20:35 +00:00
// write build logs to db
2015-12-02 21:27:09 +00:00
db.logLines.put(lines, function(err) {
if (err) {
logger.error(
'Error during write log line "' + logLineNumber +
'" for build "' + build.id + '":',
err.stack || err
);
}
});
});
callback(null, distributor);
};