I am using the bull queue to process jobs.
Let's say a job is running with a status of active
when I restart my dev server. When the worker script starts up again, the process is still set to active
in the queue, so bull decides to start up the worker process again.
This become disruptive very quickly, as the script is often restarting during development, so many processes end up running and making a mess of things. All I want is bull to NOT restart these jobs when the server starts.
Things I've tried:
- setting
attempts: 1
when creating a job (also tried 0) https://github.com/OptimalBits/bull/blob/HEAD/REFERENCE.md#queueadd - using queue.clean() (https://github.com/OptimalBits/bull/blob/HEAD/REFERENCE.md#queueclean)
- Writing a script to remove active jobs (throws Error: Missing lock for job xx failed):
let active_jobs = await queue.getJobs(['active']);
active_jobs.forEach(async (active_job) => {
await active_job.discard()
await active_job.moveToFailed(new Error("Auto-killed during dev server restart"))
})
None of this works. Anyone have a solution to achieve this?
It actually easy if you have the needed functions in place. You could implement some code to completely clean the specific queues. That code has to live in a place thats called one time once your server starts up. So a good place would be the constructor of your class (of the producer-server). That way you always start with a clean queue with zero entries for development purposes. So best is to wrap the function call to empty the queues into some statement that prooves for development conditions.
You can use something like the following: