I was trying to run jobs which were CPU intensive and I was getting a "Error: job stalled more than allowable limit" error. I tried increasing the lock time but with increased load, the error persisted. I then used worker threads and wrapped the consumer as a sandboxed job. The issue though persisted but with less frequency. I wanted the user to retry the jobs manually so I set maxStalledCount=0, I'm updating the failure status of the jobs in a db with jobId.
The problem I'm facing is the "job" argument on the "failed" event for a worker is at times undefined, for instance the job is undefined when bullmq moves the stalled job to "failed" because maxStalledCount=0 but it doesn't give me the "job" argument to update it in the db. So I'm simply remained with an error message.
worker.on('failed', (job, error) => {
if (job === undefined) {
// when a stalled job is moved to failed state
console.error('only error', error)
} else {
// when the job is failed from the business logic
console.error('error with job', job)
}
})
Is there a way to get jobId once the "failed" event is triggered for stalled jobs? I just need to update the job status in my db and I need a jobId for it.