mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-02-10 17:39:15 +00:00
complete uncompleted builds on server start
This commit is contained in:
parent
d5b3cee38c
commit
9b7bb39d91
@ -23,7 +23,7 @@ work in progress...
|
||||
* ~~Better tests coverage~~
|
||||
* ~~Compile client for production~~
|
||||
* Semantic versioning and plugins
|
||||
* Complete uncompleted builds on server start
|
||||
* ~~Complete uncompleted builds on server start~~
|
||||
|
||||
Ui fixes
|
||||
|
||||
|
74
app.js
74
app.js
@ -62,6 +62,78 @@ var configDefaults = {
|
||||
http: {host: '127.0.0.1', port: 3000, url: 'http://127.0.0.1:3000'}
|
||||
};
|
||||
|
||||
var completeUncompletedBuilds = function(callback) {
|
||||
Steppy(
|
||||
function() {
|
||||
db.builds.find({
|
||||
start: {descCreateDate: ''},
|
||||
filter: function(build) {
|
||||
return !build.completed;
|
||||
},
|
||||
limit: 100
|
||||
}, this.slot());
|
||||
},
|
||||
function(err, uncompletedBuilds) {
|
||||
var completeGroup = this.makeGroup();
|
||||
|
||||
if (uncompletedBuilds.length) {
|
||||
var queuedAndOtherUncompletedBuilds = _(uncompletedBuilds).partition(
|
||||
function(uncompletedBuild) {
|
||||
return uncompletedBuild.status === 'queued';
|
||||
}
|
||||
);
|
||||
|
||||
var queuedBuilds = queuedAndOtherUncompletedBuilds[0];
|
||||
uncompletedBuilds = queuedAndOtherUncompletedBuilds[1];
|
||||
|
||||
if (queuedBuilds.length) {
|
||||
logger.log(
|
||||
'remove queued builds: %s',
|
||||
_(queuedBuilds).pluck('id').join(', ')
|
||||
);
|
||||
|
||||
db.builds.del(queuedBuilds, completeGroup.slot());
|
||||
}
|
||||
|
||||
if (uncompletedBuilds.length) {
|
||||
logger.log(
|
||||
'complete with interrupt error uncompleted builds: %s',
|
||||
_(uncompletedBuilds).pluck('id').join(', ')
|
||||
);
|
||||
|
||||
_(uncompletedBuilds).each(function(uncompletedBuild) {
|
||||
var endDate = (
|
||||
uncompletedBuild.startDate ||
|
||||
uncompletedBuild.createDate
|
||||
);
|
||||
|
||||
var sumDuration = _(uncompletedBuild.stepTimings).reduce(
|
||||
function(sum, timing) {
|
||||
return sum + timing.duration;
|
||||
},
|
||||
0
|
||||
) || 0;
|
||||
|
||||
endDate += sumDuration;
|
||||
|
||||
db.builds.update(
|
||||
{id: uncompletedBuild.id},
|
||||
{
|
||||
endDate: endDate,
|
||||
status: 'error',
|
||||
completed: true,
|
||||
error: {message: 'interrupted by server restart'}
|
||||
},
|
||||
completeGroup.slot()
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
callback
|
||||
);
|
||||
};
|
||||
|
||||
Steppy(
|
||||
function() {
|
||||
app.config = {};
|
||||
@ -116,6 +188,8 @@ Steppy(
|
||||
function() {
|
||||
// load all projects for the first time
|
||||
project.loadAll(app.config.paths.projects, this.slot());
|
||||
|
||||
completeUncompletedBuilds(this.slot());
|
||||
},
|
||||
function(err, projects) {
|
||||
// note that `app.projects` is live variable
|
||||
|
Loading…
Reference in New Issue
Block a user