mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-01-25 22:16:16 +00:00
88 lines
2.0 KiB
JavaScript
88 lines
2.0 KiB
JavaScript
'use strict';
|
|
|
|
var Steppy = require('twostep').Steppy,
|
|
EventEmitter = require('events').EventEmitter,
|
|
inherits = require('util').inherits;
|
|
|
|
/**
|
|
* Facade entity which accumulates operations with currently running and
|
|
* db saved builds.
|
|
*/
|
|
function BuildsCollection(params) {
|
|
this.db = params.db;
|
|
this.distributor = params.distributor;
|
|
}
|
|
|
|
exports.BuildsCollection = BuildsCollection;
|
|
|
|
inherits(BuildsCollection, EventEmitter);
|
|
|
|
BuildsCollection.prototype.create = function(params, callback) {
|
|
this.distributor.run(params, callback);
|
|
};
|
|
|
|
BuildsCollection.prototype.cancel = function(params, callback) {
|
|
this.distributor.cancel(params, callback);
|
|
};
|
|
|
|
BuildsCollection.prototype.get = function(id, callback) {
|
|
this.find({start: {id: id}}, function(err, builds) {
|
|
callback(err, builds && builds[0]);
|
|
});
|
|
};
|
|
|
|
BuildsCollection.prototype.find = function(params, callback) {
|
|
this.db.builds.find(params, callback);
|
|
};
|
|
|
|
BuildsCollection.prototype.getLogLines = function(params, callback) {
|
|
var self = this;
|
|
|
|
Steppy(
|
|
function() {
|
|
var findParams = {
|
|
start: {buildId: params.buildId},
|
|
end: {buildId: params.buildId}
|
|
};
|
|
if (params.from) findParams.start.number = params.from;
|
|
if (params.to) findParams.end.number = params.to;
|
|
|
|
var count = params.from && params.to ? params.to - params.from + 1: 0;
|
|
|
|
self.db.logLines.find(findParams, this.slot());
|
|
|
|
this.pass(count);
|
|
},
|
|
function(err, logLines, count) {
|
|
this.pass({
|
|
lines: logLines,
|
|
isLast: count ? logLines.length < count : true
|
|
});
|
|
},
|
|
callback
|
|
);
|
|
};
|
|
|
|
BuildsCollection.prototype.getLogLinesTail = function(params, callback) {
|
|
var self = this;
|
|
|
|
Steppy(
|
|
function() {
|
|
var findParams = {
|
|
reverse: true,
|
|
start: {buildId: params.buildId},
|
|
limit: params.limit
|
|
};
|
|
|
|
self.db.logLines.find(findParams, this.slot());
|
|
},
|
|
function(err, logLines) {
|
|
var lines = logLines.reverse(),
|
|
total = logLines.length ? logLines[logLines.length - 1].number : 0;
|
|
|
|
this.pass({lines: lines, total: total});
|
|
},
|
|
callback
|
|
);
|
|
};
|