Add debug information in Jobs Queue

This commit is contained in:
Raul Ochoa 2016-10-17 18:16:52 +02:00
parent c6e906d3ef
commit a8e03f01c9

View File

@ -1,5 +1,7 @@
'use strict';
var debug = require('./util/debug')('queue');
function JobQueue(metadataBackend, jobPublisher) {
this.metadataBackend = metadataBackend;
this.jobPublisher = jobPublisher;
@ -14,16 +16,15 @@ var QUEUE = {
module.exports.QUEUE = QUEUE;
JobQueue.prototype.enqueue = function (user, jobId, callback) {
var self = this;
debug('JobQueue.enqueue user=%s, jobId=%s', user, jobId);
this.metadataBackend.redisCmd(QUEUE.DB, 'LPUSH', [ QUEUE.PREFIX + user, jobId ], function (err) {
if (err) {
return callback(err);
}
self.jobPublisher.publish(user);
this.jobPublisher.publish(user);
callback();
});
}.bind(this));
};
JobQueue.prototype.size = function (user, callback) {
@ -31,9 +32,13 @@ JobQueue.prototype.size = function (user, callback) {
};
JobQueue.prototype.dequeue = function (user, callback) {
this.metadataBackend.redisCmd(QUEUE.DB, 'RPOP', [ QUEUE.PREFIX + user ], callback);
this.metadataBackend.redisCmd(QUEUE.DB, 'RPOP', [ QUEUE.PREFIX + user ], function(err, jobId) {
debug('JobQueue.dequeued user=%s, jobId=%s', user, jobId);
return callback(err, jobId);
});
};
JobQueue.prototype.enqueueFirst = function (user, jobId, callback) {
debug('JobQueue.enqueueFirst user=%s, jobId=%s', user, jobId);
this.metadataBackend.redisCmd(QUEUE.DB, 'RPUSH', [ QUEUE.PREFIX + user, jobId ], callback);
};