'use strict';

function JobQueue(metadataBackend, jobPublisher) {
    this.metadataBackend = metadataBackend;
    this.jobPublisher = jobPublisher;
}

module.exports = JobQueue;

var QUEUE = {
    DB: 5,
    PREFIX: 'batch:queue:'
};
module.exports.QUEUE = QUEUE;

JobQueue.prototype.enqueue = function (user, jobId, callback) {
    var self = this;

    this.metadataBackend.redisCmd(QUEUE.DB, 'LPUSH', [ QUEUE.PREFIX + user, jobId ], function (err) {
        if (err) {
            return callback(err);
        }

        self.jobPublisher.publish(user);
        callback();
    });
};

JobQueue.prototype.size = function (user, callback) {
    this.metadataBackend.redisCmd(QUEUE.DB, 'LLEN', [ QUEUE.PREFIX + user ], callback);
};

JobQueue.prototype.dequeue = function (user, callback) {
    this.metadataBackend.redisCmd(QUEUE.DB, 'RPOP', [ QUEUE.PREFIX + user ], callback);
};

JobQueue.prototype.enqueueFirst = function (user, jobId, callback) {
    this.metadataBackend.redisCmd(QUEUE.DB, 'RPUSH', [ QUEUE.PREFIX + user, jobId ], callback);
};

@@ -8,16 +8,63 @@
 rict';%0A%0A
+var debug = require('./util/debug')('queue');%0A%0A
 function
@@ -377,25 +377,65 @@
     
-var self = this;%0A
+debug('JobQueue.enqueue user=%25s, jobId=%25s', user, jobId);
 %0A   
@@ -609,12 +609,12 @@
     
-self
+this
 .job
@@ -663,16 +663,27 @@
 );%0A    %7D
+.bind(this)
 );%0A%7D;%0A%0AJ
@@ -957,32 +957,156 @@
 X + user %5D, 
-callback
+function(err, jobId) %7B%0A        debug('JobQueue.dequeued user=%25s, jobId=%25s', user, jobId);%0A        return callback(err, jobId);%0A    %7D
 );%0A%7D;%0A%0AJobQu
@@ -1161,32 +1161,99 @@
 Id, callback) %7B%0A
+    debug('JobQueue.enqueueFirst user=%25s, jobId=%25s', user, jobId);%0A
     this.metadat

Add debug information in Jobs Queue