Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(retry): extend explanation #2164

Merged
merged 3 commits into from
Nov 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)