@@ -3,15 +3,19 @@ Errors and retryable jobs
3
3
4
4
The execution of a job can fail. This can be due to internal errors which result from
5
5
poorly written code which should be fixed first. But they can also fail due to external
6
- problems like a service or a resource being unavailable. This can lead to Exceptions or
6
+ problems like a service or a resource being unavailable. This can lead to exceptions or
7
7
timeouts.
8
8
9
9
In the latter cases, it's good to be able to retry a job after some time. There are several ways to do this.
10
10
11
+ > ** Note:** The ` ttr ` feature described below requires the
12
+ > [ PHP Process Control (pcntl) extension] ( http://php.net/manual/en/book.pcntl.php ) to be installed
13
+ > and the worker command has to use the ` --isolate ` option (which is enabled by default).
14
+
11
15
Retry options
12
16
-------------
13
17
14
- The first method is to use component options:
18
+ The first method is to use queue component options:
15
19
16
20
``` php
17
21
'components' => [
@@ -23,9 +27,19 @@ The first method is to use component options:
23
27
],
24
28
```
25
29
26
- The ` ttr ` option sets the time to reserve for job execution. If the execution of a job takes longer than
27
- this time, execution will be stopped and it will be returned to the queue for later retry. The same happens
28
- if the job throws an Exception. The ` attempts ` option sets the max. number of attempts. If this number is
30
+ The ` ttr ` (Time to reserve, TTR) option defines the number of seconds during which a job must
31
+ be successfully completed. So two things can happen to make a job fail:
32
+
33
+ 1 . The job throws an exception before ` ttr ` is over
34
+ 2 . It would take longer than ` ttr ` to complete the job (timeout) and thus the
35
+ job execution is stopped by the worker.
36
+
37
+ In both cases, the job will be sent back to the queue for a retry. Note though,
38
+ that in the first case the ` ttr ` is still "used up" even if the job stops right
39
+ after it has stared. I.e. the remaining seconds of ` ttr ` have to pass before the
40
+ job is sent back to the queue.
41
+
42
+ The ` attempts ` option sets the max. number of attempts. If this number is
29
43
reached, and the job still isn't done, it will be removed from the queue as completed.
30
44
31
45
These options apply to all jobs in the queue. If you need to change this behavior for specific
@@ -85,7 +99,7 @@ Yii::$app->queue->on(Queue::EVENT_AFTER_ERROR, function (ErrorEvent $event) {
85
99
});
86
100
```
87
101
88
- Event handlers are executed after ` RetryableJobInterface ` methods, and therefore have the highest
102
+ Event handlers are executed after the ` RetryableJobInterface ` methods, and therefore have the highest
89
103
priority.
90
104
91
105
Restrictions
0 commit comments