| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c32b4a8 commit d3b0916
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,6 +31,7 @@ Contents | |||
| 31 | 31 | ||
| 32 | 32 | components | |
| 33 | 33 | locking | |
| 34 | + retry | ||
| 34 | 35 | quick-example | |
| 35 | 36 | symfony | |
| 36 | 37 | ||
| Original file line number | Diff line number | Diff 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 | + | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments