1 | <?php |
||
14 | class RetryProcessor implements ProcessorInterface |
||
15 | { |
||
16 | const PROPERTY_KEY = 'attempt'; |
||
17 | |||
18 | /** |
||
19 | * @var ProcessorInterface |
||
20 | */ |
||
21 | protected $processor; |
||
22 | |||
23 | /** |
||
24 | * @var RetryStrategyInterface |
||
25 | */ |
||
26 | protected $strategy; |
||
27 | |||
28 | /** |
||
29 | * @var LoggerInterface |
||
30 | */ |
||
31 | protected $logger; |
||
32 | |||
33 | /** |
||
34 | * @var int |
||
35 | */ |
||
36 | protected $maxAttempts = 2; |
||
37 | |||
38 | /** |
||
39 | * @param ProcessorInterface $processor |
||
40 | * @param RetryStrategyInterface $strategy |
||
41 | * @param LoggerInterface $logger |
||
42 | */ |
||
43 | 5 | public function __construct(ProcessorInterface $processor, RetryStrategyInterface $strategy, LoggerInterface $logger = null) |
|
49 | |||
50 | /** |
||
51 | * @param ProcessorInterface $processor |
||
52 | */ |
||
53 | 1 | public function setProcessor($processor) |
|
57 | |||
58 | /** |
||
59 | * @return ProcessorInterface |
||
60 | */ |
||
61 | 1 | public function getProcessor() |
|
65 | |||
66 | /** |
||
67 | * @param int $maxAttempts |
||
68 | */ |
||
69 | 2 | public function setMaxAttempts($maxAttempts) |
|
73 | |||
74 | /** |
||
75 | * @return int |
||
76 | */ |
||
77 | 1 | public function getMaxAttempts() |
|
81 | |||
82 | /** |
||
83 | * @inheritdoc |
||
84 | */ |
||
85 | 3 | public function process(EnvelopeInterface $envelope) |
|
98 | |||
99 | /** |
||
100 | * @param EnvelopeInterface $envelope |
||
101 | * @param \Exception $exception |
||
102 | * |
||
103 | * @throws ProcessExhaustedException |
||
104 | * |
||
105 | * @return bool |
||
106 | */ |
||
107 | 2 | protected function retryMessage(EnvelopeInterface $envelope, \Exception $exception = null) |
|
118 | |||
119 | /** |
||
120 | * @param EnvelopeInterface $envelope |
||
121 | * |
||
122 | * @throws \LogicException |
||
123 | * |
||
124 | * @return int |
||
125 | */ |
||
126 | 2 | protected function getAttemptValue(EnvelopeInterface $envelope) |
|
142 | } |
||
143 |