Skip to content

Commit 2f0e699

Browse files
mikehaertlcebe
authored andcommitted
Refine docs for retryable, TTR and attempts (yiisoft#229)
1 parent 3162bfb commit 2f0e699

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

docs/guide/retryable.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@ Errors and retryable jobs
33

44
The execution of a job can fail. This can be due to internal errors which result from
55
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
77
timeouts.
88

99
In the latter cases, it's good to be able to retry a job after some time. There are several ways to do this.
1010

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+
1115
Retry options
1216
-------------
1317

14-
The first method is to use component options:
18+
The first method is to use queue component options:
1519

1620
```php
1721
'components' => [
@@ -23,9 +27,19 @@ The first method is to use component options:
2327
],
2428
```
2529

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
2943
reached, and the job still isn't done, it will be removed from the queue as completed.
3044

3145
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) {
8599
});
86100
```
87101

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
89103
priority.
90104

91105
Restrictions

0 commit comments

Comments
 (0)