From 534da04270aed185b8e6c57a2abd2e9cd4527ce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Thu, 31 Dec 2015 17:01:06 +0100 Subject: [PATCH] Improved job cancelation and fixed minor bugs --- batch/batch.js | 4 ++-- batch/job_canceller.js | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/batch/batch.js b/batch/batch.js index fdfe73df..34934763 100644 --- a/batch/batch.js +++ b/batch/batch.js @@ -70,9 +70,9 @@ Batch.prototype._consume = function consume(host, queue, callback) { callback(); }) .on('error', function (err) { - console.error('Error in job %s due to', job_id, err.message || err); + console.error('Error in job %s due to:', job_id, err.message || err); self.emit('job:failed', job_id); - callback(err); + callback(); }); }); }; diff --git a/batch/job_canceller.js b/batch/job_canceller.js index 25714ac1..bda2af27 100644 --- a/batch/job_canceller.js +++ b/batch/job_canceller.js @@ -28,7 +28,7 @@ JobCanceller.prototype.cancel = function (job_id) { } if (job.status !== 'running') { - return jobBackend.emit('error', new Error('Job has been dispatched previously, nothing to do')); + return jobBackend.emit('error', new Error('Job is ' + job.status + ' nothing to do')); } self.userDatabaseMetadataService.getUserMetadata(job.user, function (err, userDatabaseMetadata) { @@ -47,12 +47,11 @@ JobCanceller.prototype.cancel = function (job_id) { return jobBackend.emit('error', err); } - var pid = result.rows[0].pid; - - if (!pid) { + if (!result.rows[0] || result.rows[0].pid) { return jobBackend.emit('error', new Error('Query not running currently')); } + var pid = result.rows[0].pid; var cancelQuery = 'SELECT pg_cancel_backend(' + pid +')'; pg.query(cancelQuery, function (err, result) {