-
Notifications
You must be signed in to change notification settings - Fork 4.8k
[12.x] Improve Queues and Horizon documentation #10596
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
Merged
Merged
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
a7cc30e
qg/queues
QuentinGab 52a1620
qg/horizon
QuentinGab 4c43417
format
QuentinGab 96a4084
add documentation about TimeoutExceededException
QuentinGab a57d763
Clarify timeout doc
QuentinGab db11c73
rewrite strategies
QuentinGab 5f32368
typo
QuentinGab 0471e2c
format
QuentinGab cd779cc
format
QuentinGab 17caa35
simplify
QuentinGab 982ad73
simplify
QuentinGab a9aeeea
Correct False Strategy
QuentinGab f2eb5ff
use min/maxProcesses instead of processes
QuentinGab 433ec8b
rewrite simple strategy
QuentinGab 61476ee
typo
QuentinGab 4784ecc
simplify false
QuentinGab 2a739d1
reformulate
QuentinGab 5f34adb
reformulate
QuentinGab 8ce5cda
typo
QuentinGab 488f88f
remove useless comments
QuentinGab ca4b1ba
Update horizon.md
QuentinGab 74124fc
Update horizon.md
QuentinGab 7ca7357
Update horizon.md
QuentinGab c34775f
Update horizon.md
QuentinGab b943c15
Update horizon.md
QuentinGab 06ba5f5
Update horizon.md
QuentinGab 5276d3c
Update horizon.md
QuentinGab c6ed095
Update horizon.md
QuentinGab 92b25aa
Update queues.md
QuentinGab 6643d6a
Update queues.md
QuentinGab e611995
Update queues.md
QuentinGab 5ee2e44
Update queues.md
QuentinGab 3aa2749
Update queues.md
QuentinGab f5caca9
Update queues.md
QuentinGab 0ed768e
remove new line
QuentinGab 27faca4
Update queues.md
QuentinGab be14f12
Update queues.md
QuentinGab b6b2703
Update queues.md
QuentinGab 08c8ad3
Update queues.md
QuentinGab 95912df
Update horizon.md
QuentinGab 740e07a
format
QuentinGab 560e119
reformulate
QuentinGab 513c96f
reformulate
QuentinGab c2531c8
add context
QuentinGab 32e1126
wording
QuentinGab 399613b
formatting
taylorotwell 4c19269
rearrange
taylorotwell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -577,6 +577,8 @@ public function middleware(): array | |
} | ||
``` | ||
|
||
Releasing an overlapping job back onto the queue will still increment the job's total number of attempts. You may wish to tune your `tries` and `maxExceptions` properties on your job class accordingly. For example, leaving the `tries` property to 1 as it is by default would prevent any overlapping job from being retried later. | ||
|
||
Any overlapping jobs of the same type will be released back to the queue. You may also specify the number of seconds that must elapse before the released job will be attempted again: | ||
|
||
```php | ||
|
@@ -1213,7 +1215,26 @@ class ProcessPodcast implements ShouldQueue | |
<a name="max-attempts"></a> | ||
#### Max Attempts | ||
|
||
If one of your queued jobs is encountering an error, you likely do not want it to keep retrying indefinitely. Therefore, Laravel provides various ways to specify how many times or for how long a job may be attempted. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This section was confusing to me, as it mixed errors and attempts, so I tried to explain as clearly as possible what an ‘attempt’ is. |
||
Job attempts are a core concept of Laravel's queue system and power many advanced features. While they may seem confusing at first, it's important to understand how they work before modifying the default configuration. | ||
|
||
When a job is dispatched, it is pushed onto the queue. A worker then picks it up and attempts to execute it. This is a job attempt. | ||
|
||
However, an attempt does not necessarily mean the job's `handle` method was executed. Attempts can also be "consumed" in several ways: | ||
|
||
<div class="content-list" markdown="1"> | ||
|
||
- The job encounters an unhandled exception during execution. | ||
- The job is manually released back to the queue using `$this->release()`. | ||
- Middleware such as `WithoutOverlapping` or `RateLimited` fails to acquire a lock and releases the job. | ||
- The job timed out. | ||
- The job's `handle` method runs and completes without throwing an exception. | ||
|
||
</div> | ||
|
||
You likely do not want to keep attempting a job indefinitely. Therefore, Laravel provides various ways to specify how many times or for how long a job may be attempted. | ||
|
||
> [!NOTE] | ||
> By default, Laravel will only attempt a job once. If your job uses middleware like `WithoutOverlapping` or `RateLimited`, or if you're manually releasing jobs, you will likely need to increase the number of allowed attempts via the `tries` option. | ||
|
||
One approach to specifying the maximum number of times a job may be attempted is via the `--tries` switch on the Artisan command line. This will apply to all jobs processed by the worker unless the job being processed specifies the number of times it may be attempted: | ||
|
||
|
@@ -1370,6 +1391,9 @@ If you would like to indicate that a job should be marked as [failed](#dealing-w | |
public $failOnTimeout = true; | ||
``` | ||
|
||
> [!NOTE] | ||
> By default, when a job times out, it consumes one attempt and is released back to the queue (if retries are allowed). However, if you configure the job to fail on timeout, it will not be retried, regardless of the value set for tries. | ||
|
||
<a name="error-handling"></a> | ||
### Error Handling | ||
|
||
|
@@ -2249,6 +2273,18 @@ class ProcessPodcast implements ShouldQueue | |
> [!WARNING] | ||
> A new instance of the job is instantiated before invoking the `failed` method; therefore, any class property modifications that may have occurred within the `handle` method will be lost. | ||
|
||
A failed job is not necessarily one that encountered an unhandled exception. A job may also be considered failed when it has exhausted all of its allowed attempts. These attempts can be consumed in several ways: | ||
|
||
<div class="content-list" markdown="1"> | ||
|
||
- The job timed out. | ||
- The job encounters an unhandled exception during execution. | ||
- The job is released back to the queue either manually or by a middleware. | ||
|
||
</div> | ||
|
||
If the final attempt fails due to an exception thrown during job execution, that exception will be passed to the job's failed method. However, if the job fails because it has reached the maximum number of allowed attempts, the `$exception` will be an instance of `Illuminate\Queue\MaxAttemptsExceededException`. Similarly, if the job fails due to exceeding the configured timeout, the `$exception` will be an instance of `Illuminate\Queue\TimeoutExceededException`. | ||
|
||
<a name="retrying-failed-jobs"></a> | ||
### Retrying Failed Jobs | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.