3

I'm using Bull with NestJS to handle a jobs queue. In the process handler I would like to mark a job as failed instead of completed, but it seems - also reading the documentation - that the Job#moveToFailed() method is allowed only on waiting jobs.

In fact, it triggers an error saying "Missing lock for job ${jobId} failed". But, calling the Job#moveToFailed with the ignoreLock parameter to true everything goes fine.

What happens if I ignore the lock moving a job to failed? Is there some side effect? In my scenario, the queue jobs will be always consumed by the same @Processor.

Here it is the piece of code I'm running for test purpose:

@Process()
async transcode(job: Job<unknown>): Promise<any> {
  const jobData = job.data as Record<string, string | unknown>
  if (jobData == null) {
    await job.moveToFailed({ message: 'Hook marked as failed because of missing data' })
    return
  }

  // do other stuff for job execution..
}
andrea.rinaldi
  • 1,167
  • 1
  • 13
  • 33

1 Answers1

1

You can pass false as a token parameter (that ignores the token check).

await job.moveToFailed({ message: 'Hook marked as failed because of missing data' }, false)

I was able to add '0' instead of false and that worked for me, but the parameter type is Boolean like mentioned in the comments below.

jakobinn
  • 1,832
  • 1
  • 20
  • 20