From 5b8108d4a8a1420267d0bff54c60f1e699651d6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Thu, 27 Oct 2016 18:00:56 +0200 Subject: [PATCH] Use job service to add jobs to work-in-progress list --- batch/batch.js | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/batch/batch.js b/batch/batch.js index 067b129a..03e7a6b8 100644 --- a/batch/batch.js +++ b/batch/batch.js @@ -63,26 +63,31 @@ Batch.prototype.processJob = function (user, callback) { return callback(null, EMPTY_QUEUE); } - self.setWorkInProgressJob(user, jobId); - self.jobRunner.run(jobId, function (err, job) { - self.clearWorkInProgressJob(user); - + self.setWorkInProgressJob(user, jobId, function (err) { if (err) { - debug(err); - if (err.name === 'JobNotRunnable') { - return callback(null, !EMPTY_QUEUE); - } - return callback(err, !EMPTY_QUEUE); + return callback(new Error('Could not add job to work-in-progress list. Reason: ' + err.message)); } - debug( - '[%s] Job=%s status=%s user=%s (failed_reason=%s)', - self.name, jobId, job.data.status, user, job.failed_reason - ); + self.jobRunner.run(jobId, function (err, job) { + self.clearWorkInProgressJob(user); - self.logger.log(job); + if (err) { + debug(err); + if (err.name === 'JobNotRunnable') { + return callback(null, !EMPTY_QUEUE); + } + return callback(err, !EMPTY_QUEUE); + } - return callback(null, !EMPTY_QUEUE); + debug( + '[%s] Job=%s status=%s user=%s (failed_reason=%s)', + self.name, jobId, job.data.status, user, job.failed_reason + ); + + self.logger.log(job); + + return callback(null, !EMPTY_QUEUE); + }); }); }); }; @@ -138,8 +143,9 @@ Batch.prototype.stop = function (callback) { /* Work in progress jobs */ -Batch.prototype.setWorkInProgressJob = function(user, jobId) { +Batch.prototype.setWorkInProgressJob = function(user, jobId, callback) { this.workInProgressJobs[user] = jobId; + this.jobService.addWorkInProgressJob(user, jobId, callback); }; Batch.prototype.getWorkInProgressJob = function(user) {