2015-04-10 19:23:52 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-07-05 17:18:51 +00:00
|
|
|
var _ = require('underscore'),
|
2016-01-07 07:52:01 +00:00
|
|
|
errorHandler = require('./errorHandler'),
|
2016-01-07 19:02:59 +00:00
|
|
|
helpers = require('./helpers');
|
2015-04-10 19:23:52 +00:00
|
|
|
|
2015-05-03 15:23:01 +00:00
|
|
|
module.exports = function(app) {
|
2015-04-10 19:23:52 +00:00
|
|
|
_(['builds', 'projects']).each(function(resource) {
|
2015-07-05 17:18:51 +00:00
|
|
|
var resource = require('./' + resource)(app);
|
|
|
|
resource.use(errorHandler);
|
2015-04-10 19:23:52 +00:00
|
|
|
});
|
2016-01-07 07:52:01 +00:00
|
|
|
|
|
|
|
var buildsResource = app.dataio.resource('builds');
|
|
|
|
|
|
|
|
app.builds.on('buildUpdated', function(build, changes) {
|
|
|
|
if (build.status === 'queued') {
|
2016-01-07 19:02:59 +00:00
|
|
|
helpers.createBuildDataResource(app, build.id);
|
2016-01-07 07:52:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// notify about build's project change, coz building affects project
|
|
|
|
// related stat (last build date, avg build time, etc)
|
|
|
|
if (changes.completed) {
|
|
|
|
var projectsResource = app.dataio.resource('projects');
|
|
|
|
projectsResource.clientEmitSyncChange(build.project.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
buildsResource.clientEmitSync('change', {
|
|
|
|
buildId: build.id, changes: changes
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
app.builds.on('buildCanceled', function(build) {
|
|
|
|
buildsResource.clientEmitSync('cancel', {buildId: build.id});
|
|
|
|
});
|
|
|
|
|
|
|
|
app.builds.on('buildLogLines', function(build, lines) {
|
|
|
|
app.dataio.resource('build' + build.id).clientEmitSync(
|
|
|
|
'data',
|
|
|
|
{lines: lines}
|
|
|
|
);
|
|
|
|
});
|
2015-04-10 19:23:52 +00:00
|
|
|
};
|