@@ -12,7 +12,7 @@ |
||
12 | 12 | public function __construct( |
13 | 13 | private readonly bool $retryable = true, |
14 | 14 | private readonly ?RetryPolicyInterface $retryPolicy = null |
15 | - ) { |
|
15 | + ){ |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | public function isRetryable(): bool |
@@ -79,9 +79,9 @@ discard block |
||
79 | 79 | ->with(self::class, 'bar', []) |
80 | 80 | ->willThrowException(new TestRetryException()); |
81 | 81 | |
82 | - try { |
|
82 | + try{ |
|
83 | 83 | $this->interceptor->process(self::class, 'bar', [], $this->core); |
84 | - } catch (RetryException $e) { |
|
84 | + }catch (RetryException $e){ |
|
85 | 85 | $this->assertSame(1, $e->getOptions()->getDelay()); |
86 | 86 | $this->assertSame(['attempts' => ['1']], $e->getOptions()->getHeaders()); |
87 | 87 | } |
@@ -99,14 +99,14 @@ discard block |
||
99 | 99 | ->with(self::class, 'bar', ['headers' => ['attempts' => ['1']]]) |
100 | 100 | ->willThrowException(new TestRetryException()); |
101 | 101 | |
102 | - try { |
|
102 | + try{ |
|
103 | 103 | $this->interceptor->process( |
104 | 104 | self::class, |
105 | 105 | 'bar', |
106 | 106 | ['headers' => ['attempts' => ['1']]], |
107 | 107 | $this->core |
108 | 108 | ); |
109 | - } catch (RetryException $e) { |
|
109 | + }catch (RetryException $e){ |
|
110 | 110 | $this->assertSame(8, $e->getOptions()->getDelay()); |
111 | 111 | $this->assertSame(['attempts' => ['2']], $e->getOptions()->getHeaders()); |
112 | 112 | } |
@@ -126,14 +126,14 @@ discard block |
||
126 | 126 | retryPolicy: new \Spiral\Queue\RetryPolicy(maxAttempts: 3, delay: 4, multiplier: 2) |
127 | 127 | )); |
128 | 128 | |
129 | - try { |
|
129 | + try{ |
|
130 | 130 | $this->interceptor->process( |
131 | 131 | self::class, |
132 | 132 | 'bar', |
133 | 133 | ['headers' => ['attempts' => ['1']]], |
134 | 134 | $this->core |
135 | 135 | ); |
136 | - } catch (RetryException $e) { |
|
136 | + }catch (RetryException $e){ |
|
137 | 137 | $this->assertSame(8, $e->getOptions()->getDelay()); |
138 | 138 | $this->assertSame(['attempts' => ['2']], $e->getOptions()->getHeaders()); |
139 | 139 | } |
@@ -155,14 +155,14 @@ discard block |
||
155 | 155 | ) |
156 | 156 | )); |
157 | 157 | |
158 | - try { |
|
158 | + try{ |
|
159 | 159 | $this->interceptor->process( |
160 | 160 | self::class, |
161 | 161 | 'bar', |
162 | 162 | ['headers' => ['attempts' => ['1']]], |
163 | 163 | $this->core |
164 | 164 | ); |
165 | - } catch (RetryException $e) { |
|
165 | + }catch (RetryException $e){ |
|
166 | 166 | $this->assertSame(8, $e->getOptions()->getDelay()); |
167 | 167 | $this->assertSame(['attempts' => ['2']], $e->getOptions()->getHeaders()); |
168 | 168 | } |
@@ -79,9 +79,12 @@ discard block |
||
79 | 79 | ->with(self::class, 'bar', []) |
80 | 80 | ->willThrowException(new TestRetryException()); |
81 | 81 | |
82 | - try { |
|
82 | + try |
|
83 | + { |
|
83 | 84 | $this->interceptor->process(self::class, 'bar', [], $this->core); |
84 | - } catch (RetryException $e) { |
|
85 | + } |
|
86 | + catch (RetryException $e) |
|
87 | + { |
|
85 | 88 | $this->assertSame(1, $e->getOptions()->getDelay()); |
86 | 89 | $this->assertSame(['attempts' => ['1']], $e->getOptions()->getHeaders()); |
87 | 90 | } |
@@ -99,14 +102,17 @@ discard block |
||
99 | 102 | ->with(self::class, 'bar', ['headers' => ['attempts' => ['1']]]) |
100 | 103 | ->willThrowException(new TestRetryException()); |
101 | 104 | |
102 | - try { |
|
105 | + try |
|
106 | + { |
|
103 | 107 | $this->interceptor->process( |
104 | 108 | self::class, |
105 | 109 | 'bar', |
106 | 110 | ['headers' => ['attempts' => ['1']]], |
107 | 111 | $this->core |
108 | 112 | ); |
109 | - } catch (RetryException $e) { |
|
113 | + } |
|
114 | + catch (RetryException $e) |
|
115 | + { |
|
110 | 116 | $this->assertSame(8, $e->getOptions()->getDelay()); |
111 | 117 | $this->assertSame(['attempts' => ['2']], $e->getOptions()->getHeaders()); |
112 | 118 | } |
@@ -126,14 +132,17 @@ discard block |
||
126 | 132 | retryPolicy: new \Spiral\Queue\RetryPolicy(maxAttempts: 3, delay: 4, multiplier: 2) |
127 | 133 | )); |
128 | 134 | |
129 | - try { |
|
135 | + try |
|
136 | + { |
|
130 | 137 | $this->interceptor->process( |
131 | 138 | self::class, |
132 | 139 | 'bar', |
133 | 140 | ['headers' => ['attempts' => ['1']]], |
134 | 141 | $this->core |
135 | 142 | ); |
136 | - } catch (RetryException $e) { |
|
143 | + } |
|
144 | + catch (RetryException $e) |
|
145 | + { |
|
137 | 146 | $this->assertSame(8, $e->getOptions()->getDelay()); |
138 | 147 | $this->assertSame(['attempts' => ['2']], $e->getOptions()->getHeaders()); |
139 | 148 | } |
@@ -155,14 +164,17 @@ discard block |
||
155 | 164 | ) |
156 | 165 | )); |
157 | 166 | |
158 | - try { |
|
167 | + try |
|
168 | + { |
|
159 | 169 | $this->interceptor->process( |
160 | 170 | self::class, |
161 | 171 | 'bar', |
162 | 172 | ['headers' => ['attempts' => ['1']]], |
163 | 173 | $this->core |
164 | 174 | ); |
165 | - } catch (RetryException $e) { |
|
175 | + } |
|
176 | + catch (RetryException $e) |
|
177 | + { |
|
166 | 178 | $this->assertSame(8, $e->getOptions()->getDelay()); |
167 | 179 | $this->assertSame(['attempts' => ['2']], $e->getOptions()->getHeaders()); |
168 | 180 | } |
@@ -30,21 +30,21 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function __construct(int $maxAttempts, int $delay, float $multiplier = 1) |
32 | 32 | { |
33 | - if ($maxAttempts < 0) { |
|
33 | + if ($maxAttempts < 0){ |
|
34 | 34 | throw new InvalidArgumentException( |
35 | 35 | \sprintf('Maximum attempts must be greater than or equal to zero: `%s` given.', $maxAttempts) |
36 | 36 | ); |
37 | 37 | } |
38 | 38 | $this->maxAttempts = $maxAttempts; |
39 | 39 | |
40 | - if ($delay < 0) { |
|
40 | + if ($delay < 0){ |
|
41 | 41 | throw new InvalidArgumentException( |
42 | 42 | \sprintf('Delay must be greater than or equal to zero: `%s` given.', $delay) |
43 | 43 | ); |
44 | 44 | } |
45 | 45 | $this->delay = $delay; |
46 | 46 | |
47 | - if ($multiplier < 1) { |
|
47 | + if ($multiplier < 1){ |
|
48 | 48 | throw new InvalidArgumentException( |
49 | 49 | \sprintf('Multiplier must be greater than zero: `%s` given.', $multiplier) |
50 | 50 | ); |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function getDelay(int $attempts = 0): int |
61 | 61 | { |
62 | - return (int) \ceil($this->delay * $this->multiplier ** $attempts); |
|
62 | + return (int)\ceil($this->delay * $this->multiplier ** $attempts); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -67,11 +67,11 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public function isRetryable(\Throwable $exception, int $attempts = 0): bool |
69 | 69 | { |
70 | - if ($exception instanceof JobException && $exception->getPrevious() !== null) { |
|
70 | + if ($exception instanceof JobException && $exception->getPrevious() !== null){ |
|
71 | 71 | $exception = $exception->getPrevious(); |
72 | 72 | } |
73 | 73 | |
74 | - if (!$exception instanceof RetryableExceptionInterface || $this->maxAttempts === 0) { |
|
74 | + if (!$exception instanceof RetryableExceptionInterface || $this->maxAttempts === 0){ |
|
75 | 75 | return false; |
76 | 76 | } |
77 | 77 |
@@ -30,21 +30,24 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function __construct(int $maxAttempts, int $delay, float $multiplier = 1) |
32 | 32 | { |
33 | - if ($maxAttempts < 0) { |
|
33 | + if ($maxAttempts < 0) |
|
34 | + { |
|
34 | 35 | throw new InvalidArgumentException( |
35 | 36 | \sprintf('Maximum attempts must be greater than or equal to zero: `%s` given.', $maxAttempts) |
36 | 37 | ); |
37 | 38 | } |
38 | 39 | $this->maxAttempts = $maxAttempts; |
39 | 40 | |
40 | - if ($delay < 0) { |
|
41 | + if ($delay < 0) |
|
42 | + { |
|
41 | 43 | throw new InvalidArgumentException( |
42 | 44 | \sprintf('Delay must be greater than or equal to zero: `%s` given.', $delay) |
43 | 45 | ); |
44 | 46 | } |
45 | 47 | $this->delay = $delay; |
46 | 48 | |
47 | - if ($multiplier < 1) { |
|
49 | + if ($multiplier < 1) |
|
50 | + { |
|
48 | 51 | throw new InvalidArgumentException( |
49 | 52 | \sprintf('Multiplier must be greater than zero: `%s` given.', $multiplier) |
50 | 53 | ); |
@@ -67,11 +70,13 @@ discard block |
||
67 | 70 | */ |
68 | 71 | public function isRetryable(\Throwable $exception, int $attempts = 0): bool |
69 | 72 | { |
70 | - if ($exception instanceof JobException && $exception->getPrevious() !== null) { |
|
73 | + if ($exception instanceof JobException && $exception->getPrevious() !== null) |
|
74 | + { |
|
71 | 75 | $exception = $exception->getPrevious(); |
72 | 76 | } |
73 | 77 | |
74 | - if (!$exception instanceof RetryableExceptionInterface || $this->maxAttempts === 0) { |
|
78 | + if (!$exception instanceof RetryableExceptionInterface || $this->maxAttempts === 0) |
|
79 | + { |
|
75 | 80 | return false; |
76 | 81 | } |
77 | 82 |
@@ -18,16 +18,16 @@ discard block |
||
18 | 18 | { |
19 | 19 | public function __construct( |
20 | 20 | private readonly ReaderInterface $reader |
21 | - ) { |
|
21 | + ){ |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | public function process(string $controller, string $action, array $parameters, CoreInterface $core): mixed |
25 | 25 | { |
26 | - try { |
|
26 | + try{ |
|
27 | 27 | return $core->callAction($controller, $action, $parameters); |
28 | - } catch (\Throwable $e) { |
|
28 | + }catch (\Throwable $e){ |
|
29 | 29 | $attribute = $this->reader->firstClassMetadata(new \ReflectionClass($controller), Attribute::class); |
30 | - if ($attribute === null) { |
|
30 | + if ($attribute === null){ |
|
31 | 31 | throw $e; |
32 | 32 | } |
33 | 33 | |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | $headers = $parameters['headers'] ?? []; |
37 | 37 | $attempts = (int)($headers['attempts'][0] ?? 0); |
38 | 38 | |
39 | - if ($policy->isRetryable($e, $attempts) === false) { |
|
39 | + if ($policy->isRetryable($e, $attempts) === false){ |
|
40 | 40 | throw $e; |
41 | 41 | } |
42 | 42 | |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | |
52 | 52 | private function getRetryPolicy(\Throwable $exception, Attribute $attribute): RetryPolicy |
53 | 53 | { |
54 | - if ($exception instanceof JobException && $exception->getPrevious() !== null) { |
|
54 | + if ($exception instanceof JobException && $exception->getPrevious() !== null){ |
|
55 | 55 | $exception = $exception->getPrevious(); |
56 | 56 | } |
57 | 57 |
@@ -23,11 +23,15 @@ discard block |
||
23 | 23 | |
24 | 24 | public function process(string $controller, string $action, array $parameters, CoreInterface $core): mixed |
25 | 25 | { |
26 | - try { |
|
26 | + try |
|
27 | + { |
|
27 | 28 | return $core->callAction($controller, $action, $parameters); |
28 | - } catch (\Throwable $e) { |
|
29 | + } |
|
30 | + catch (\Throwable $e) |
|
31 | + { |
|
29 | 32 | $attribute = $this->reader->firstClassMetadata(new \ReflectionClass($controller), Attribute::class); |
30 | - if ($attribute === null) { |
|
33 | + if ($attribute === null) |
|
34 | + { |
|
31 | 35 | throw $e; |
32 | 36 | } |
33 | 37 | |
@@ -36,7 +40,8 @@ discard block |
||
36 | 40 | $headers = $parameters['headers'] ?? []; |
37 | 41 | $attempts = (int)($headers['attempts'][0] ?? 0); |
38 | 42 | |
39 | - if ($policy->isRetryable($e, $attempts) === false) { |
|
43 | + if ($policy->isRetryable($e, $attempts) === false) |
|
44 | + { |
|
40 | 45 | throw $e; |
41 | 46 | } |
42 | 47 | |
@@ -51,7 +56,8 @@ discard block |
||
51 | 56 | |
52 | 57 | private function getRetryPolicy(\Throwable $exception, Attribute $attribute): RetryPolicy |
53 | 58 | { |
54 | - if ($exception instanceof JobException && $exception->getPrevious() !== null) { |
|
59 | + if ($exception instanceof JobException && $exception->getPrevious() !== null) |
|
60 | + { |
|
55 | 61 | $exception = $exception->getPrevious(); |
56 | 62 | } |
57 | 63 |
@@ -32,7 +32,7 @@ |
||
32 | 32 | protected readonly int $maxAttempts = 3, |
33 | 33 | protected readonly int $delay = 1, |
34 | 34 | protected readonly float $multiplier = 1 |
35 | - ) { |
|
35 | + ){ |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | public function getRetryPolicy(): RetryPolicyInterface |