-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathretry.php
More file actions
34 lines (24 loc) · 759 Bytes
/
retry.php
File metadata and controls
34 lines (24 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
declare(strict_types=1);
use Onliner\CommandBus\Builder;
use Onliner\CommandBus\Context;
use Onliner\CommandBus\Retry\RetryExtension;
use Onliner\CommandBus\Retry\Policy;
require __DIR__ . '/../vendor/autoload.php';
class MaybeFail
{
}
$retry = new RetryExtension();
$retry->policy(MaybeFail::class, new Policy\SimplePolicy(3));
$dispatcher = (new Builder())
->handle(MaybeFail::class, function (MaybeFail $command, Context $context) {
$attempts = $context->get('attempt', 1);
if ($attempts < 3) {
echo 'Fail ' , $attempts , ' times', \PHP_EOL;
throw new LogicException();
}
echo 'Executed!', \PHP_EOL;
})
->use($retry)
->build();
$dispatcher->dispatch(new MaybeFail());