Skip to content
This repository was archived by the owner on Mar 25, 2019. It is now read-only.

Commit c68e2de

Browse files
author
Sjoerd Tieleman
committed
Disable thread pool, extra check to not update exited jobs. Fixes #42
1 parent eee4939 commit c68e2de

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

lib/job.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ var JobUtils = {
5050
storage: config['database']['database'],
5151
host: config['database']['host'],
5252
port: config['database']['port'],
53+
pool: false,
5354
logging: false
5455
});
5556
}
@@ -472,6 +473,8 @@ var Job = JobUtils.getDatabase().define('Job', {
472473
return obj;
473474
},
474475
progressHandler: function(data) {
476+
if (this.hasExited) return;
477+
475478
this.lastMessage = data.toString().replace("\n",'');
476479

477480
(isNaN(this.duration) || this.duration == 0) ? this.extractDuration(data.toString()) : this.extractProgress(data.toString());
@@ -480,7 +483,7 @@ var Job = JobUtils.getDatabase().define('Job', {
480483
// successfull save
481484
}).error(function(err) {
482485
// error while saving job
483-
});
486+
});
484487
},
485488
extractDuration: function(text) {
486489
if (!this.durationBuffer) this.durationBuffer = "";
@@ -517,18 +520,21 @@ var Job = JobUtils.getDatabase().define('Job', {
517520
}
518521
},
519522
exitHandler: function(code, message) {
520-
if (!this.hasExited) {
521-
this.hasExited = true
522-
this.status = (code == 0 ? 'success' : 'failed');
523-
this.message = message;
523+
this.hasExited = true
524+
this.message = message;
524525

525-
if (this.status == 'success' && !isNaN(this.progress)) {
526-
this.progress = 1.0;
527-
}
528-
529-
this.save();
530-
this.completeCallback();
526+
if (code == 0) {
527+
this.progress = 1.0;
531528
}
529+
530+
this.status = (code == 0 ? StatusCodes.SUCCESS : StatusCodes.FAILED);
531+
this.save().success(function() {
532+
// successfull save
533+
}).error(function(err) {
534+
// error while saving job
535+
logger.log("Error while saving job: " + err)
536+
});
537+
this.completeCallback();
532538
}
533539
}
534540
});

0 commit comments

Comments
 (0)