Use job service to add jobs to work-in-progress list

This commit is contained in:
Daniel García Aubert 2016-10-27 18:00:56 +02:00
parent c1f2f9377d
commit 5b8108d4a8

View File

@ -63,26 +63,31 @@ Batch.prototype.processJob = function (user, callback) {
return callback(null, EMPTY_QUEUE); return callback(null, EMPTY_QUEUE);
} }
self.setWorkInProgressJob(user, jobId); self.setWorkInProgressJob(user, jobId, function (err) {
self.jobRunner.run(jobId, function (err, job) {
self.clearWorkInProgressJob(user);
if (err) { if (err) {
debug(err); return callback(new Error('Could not add job to work-in-progress list. Reason: ' + err.message));
if (err.name === 'JobNotRunnable') {
return callback(null, !EMPTY_QUEUE);
}
return callback(err, !EMPTY_QUEUE);
} }
debug( self.jobRunner.run(jobId, function (err, job) {
'[%s] Job=%s status=%s user=%s (failed_reason=%s)', self.clearWorkInProgressJob(user);
self.name, jobId, job.data.status, user, job.failed_reason
);
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 */ /* Work in progress jobs */
Batch.prototype.setWorkInProgressJob = function(user, jobId) { Batch.prototype.setWorkInProgressJob = function(user, jobId, callback) {
this.workInProgressJobs[user] = jobId; this.workInProgressJobs[user] = jobId;
this.jobService.addWorkInProgressJob(user, jobId, callback);
}; };
Batch.prototype.getWorkInProgressJob = function(user) { Batch.prototype.getWorkInProgressJob = function(user) {