Skip to content

Commit

Permalink
docs(retry): extend description (#2164)
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf authored Nov 1, 2023
1 parent a7f7080 commit 07855ad
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion docs/gitbook/guide/retrying-failing-jobs.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Retrying failing jobs

As your queues processes jobs, it is inevitable that over time some of these jobs will fail. In BullMQ, a job is considered failed in the following scenarios:
As your queues process jobs, it is inevitable that over time some of these jobs will fail. In BullMQ, a job is considered failed in the following scenarios:

- The processor function defined in your [Worker](https://docs.bullmq.io/guide/workers) has thrown an exception.
- The job has become [stalled](https://docs.bullmq.io/guide/jobs/stalled) and it has consumed the "max stalled count" setting.
Expand All @@ -19,6 +19,10 @@ Often it is desirable to automatically retry failed jobs so that we do not give

BullMQ supports retries of failed jobs using back-off functions. It is possible to use the **built-in** backoff functions or provide **custom** ones. If you do not specify a back-off function, the jobs will be retried without delay as soon as they fail.

{% hint style="info" %}
Retried jobs will respect their priority when they are moved back to waiting state.
{% endhint %}

#### Built-in backoff strategies

The current built-in backoff functions are "exponential" and "fixed".
Expand Down Expand Up @@ -81,6 +85,12 @@ const worker = new Worker('foo', async job => doSomeProcessing(), {
});
```

{% hint style="info" %}
If your backoffStrategy returns 0, jobs will be moved at the end of our waiting list (priority 0) or moved back to prioritized state (priority > 0).

If your backoffStrategy returns -1, jobs won't be retried, instead they will be moved to failed state.
{% endhint %}

You can then use your custom strategy when adding jobs:

```typescript
Expand Down Expand Up @@ -128,3 +138,7 @@ const worker = new Worker('foo', async job => doSomeProcessing(), {
},
});
```

## Read more:

- 💡 [Stop Retrying Jobs](../patterns/stop-retrying-jobs.md)

0 comments on commit 07855ad

Please sign in to comment.