Cleaning is broken (or I'm doing something wrong)
Created by: ghost
(this is similar to an issue I opened some time ago and then closed because I couldn't reproduce it)
If I call the clean function periodically, sooner or later I get the following error:
Error: Could not get lock for job: 2738. Cannot remove job.
This is not unlike #282 (closed) which also appeared to be triggered by cleaning, but that's ancient history at this point.
I finally found some time to write a smaller test program that triggers this error, but it probably isn't small enough. I'll trim it down, remove Ramda etc. Until the next version, this is the best I have. It takes some time to trigger the error. I made sure the process terminates when the error occurs.
Edit: updated to make it happen quicker
var Promise = require('bluebird'),
Queue = require('bull');
const
RHOST = 'localhost',
RPORT = 6379,
procTime = 40,
concurrency = 4,
jobCreationDelay = 10,
cleanDelay = 40;
var trace = (x) => {
console.log(x);
return x;
},
printJobMessage = (j) => {
trace('Processing job; here\'s a random number: ' + j.data.message);
return Promise.delay(procTime);
},
printErrorAndQuit = (e) => {
console.log(e);
process.exit(1);
};
var q = Queue('testq', RPORT, RHOST);
q.on('error', printErrorAndQuit);
q.process(concurrency, printJobMessage);
//clean every second
var cleanLoop = () => Promise
.all([
Promise.resolve('CLEANING STARTED').then(trace),
q.clean(0, 'completed'),
q.clean(0, 'failed')
])
.then(() => trace('CLEANING FINISHED'))
.delay(cleanDelay)
.then(() => process.nextTick(cleanLoop));
var addJob = (x) => {
q.add(x);
return x;
};
var jobLoop = () => Promise
.resolve({message: Math.random()})
.then(addJob)
.delay(jobCreationDelay)
.then(() => process.nextTick(jobLoop));
cleanLoop();
jobLoop();
Here's the extremely boring log. Error at the very bottom.