node-resque
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -38,4 +38,4 @@ // If a job with the same name, queue, and args is already running, put this job back in the queue and try later | ||
}else{ | ||
self.reEnqueue(function(){ | ||
callback(null, false); | ||
self.reEnqueue(function(){ | ||
callback(null, false); | ||
}); | ||
@@ -91,7 +91,3 @@ } | ||
}else{ | ||
try{ | ||
var flattenedArgs = self.args.join("-"); | ||
}catch(e){ | ||
var flattenedArgs = JSON.stringify(self.args); | ||
} | ||
var flattenedArgs = JSON.stringify(self.args); | ||
return self.worker.connection.key('workerslock', self.func, self.queue, flattenedArgs); | ||
@@ -101,2 +97,2 @@ } | ||
exports.jobLock = jobLock; | ||
exports.jobLock = jobLock; |
@@ -5,3 +5,3 @@ { | ||
"description": "an opinionated implementation of resque in node", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"homepage": "http://github.com/taskrabbit/node-resque", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -66,2 +66,33 @@ describe('plugins', function(){ | ||
describe('jobLock',function(){ | ||
it('will not lock jobs since arg objects are different', function(done){ | ||
worker1 = new specHelper.NR.worker({connection: specHelper.connectionDetails, timeout: specHelper.timeout, queues: specHelper.queue}, jobs, function(){ | ||
worker2 = new specHelper.NR.worker({connection: specHelper.connectionDetails, timeout: specHelper.timeout, queues: specHelper.queue}, jobs, function(){ | ||
var startTime = new Date().getTime(); | ||
var completed = 0; | ||
var onComplete = function(q, job, result){ | ||
completed++; | ||
if(completed == 2){ | ||
worker1.end(); | ||
worker2.end(); | ||
(new Date().getTime() - startTime).should.be.below(jobDelay * 2); | ||
done() | ||
} | ||
}; | ||
worker1.on('success', onComplete); | ||
worker2.on('success', onComplete); | ||
queue.enqueue(specHelper.queue, "slowAdd", [{name: 'Walter White'},2], function(){ | ||
queue.enqueue(specHelper.queue, "slowAdd", [{name: 'Jesse Pinkman'},2], function(){ | ||
worker1.start(); | ||
worker2.start(); | ||
}); | ||
}); | ||
worker1.on('error', function(queue, job, error){ console.log(error.stack); }) | ||
worker2.on('error', function(queue, job, error){ console.log(error.stack); }) | ||
}); | ||
}); | ||
}) | ||
it('will not run 2 jobs with the same args at the same time', function(done){ | ||
@@ -68,0 +99,0 @@ worker1 = new specHelper.NR.worker({connection: specHelper.connectionDetails, timeout: specHelper.timeout, queues: specHelper.queue}, jobs, function(){ |
62956
1590