Bull Queue retries being pushed to tail, not head

234 Views Asked by At

Using Bull queue. I have a queue that is rate limited. I would like failed jobs to be retried as soon as possible in the queue, considering the rate limits and backoff strategy. This does not seem to be the case. It seems that the failed job is pushed on, and will be processed behind other existing jobs in the queue. A contrived example:

const Bull = require('bull');
const queue = new Bull('test-queue', {
  limiter: {
    max: 1,
    duration: 1000
  }
});

queue.process(async ({ data, id }) => {
  let {fail = false} = data;
  console.log(`processing job ${id}`);

  if (fail) {
    throw new Error('Queue test error');
  }

  return `${id} completed`;  
});

queue.add({fail: true});
for(let i = 0; i < 10; i++) {
  queue.add({});
}

This always results in jobs after the first being processed, then the failed job is retried. According to bull, this should not be happening. Is my implementation wrong?

0

There are 0 best solutions below