Skip to content

Commit 62fe391

Browse files
wachterjohanneschirimoya
authored andcommitted
added retry chapter (#7)
1 parent f723168 commit 62fe391

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Contents
3131

3232
components
3333
locking
34+
retry
3435
quick-example
3536
symfony
3637

retry.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Retry
2+
=====
3+
Some of the tasks which will be executed by a handler are risky and could fail
4+
(e.g. long running, i/o ...). To allow retry of this tasks the handler is able
5+
to implement the interface ``RetryTaskHandlerInterface`` and specify a maximum
6+
amount of attempts to pass the task.
7+
8+
The retries will be scheduled as soon as possible and the following tasks will
9+
be scheduled after this retry later. This prevent the following tasks to fail
10+
because of bad starting conditions because of the previous task.
11+
12+
Example
13+
*******
14+
15+
.. code-block:: php
16+
17+
<?php
18+
19+
include __DIR__ . '/vendor/autoload.php';
20+
21+
class ImageResizeHandler implements Task\Handler\TaskHandlerInterface, Task\Executor\RetryTaskHandlerInterface
22+
{
23+
public function handle($workload)
24+
{
25+
try {
26+
$this->doSomething();
27+
} catch (SpecificException $exception) {
28+
throw new FailedException($exception);
29+
}
30+
31+
// other exceptions will be propagated to the runner
32+
// the runner will retry the execution until the max-attempts are reached
33+
}
34+
35+
public function getMaximumAttempts()
36+
{
37+
return 3;
38+
}
39+
}
40+
41+

0 commit comments

Comments
 (0)