Passed
Pull Request — master (#1025)
by butschster
09:34
created
src/Queue/tests/Interceptor/Consume/RetryPolicyInterceptorTest.php 2 patches
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -78,9 +78,9 @@  discard block
 block discarded – undo
78 78
                 retryPolicy: new \Spiral\Queue\RetryPolicy(maxAttempts: 2, delay: 4)
79 79
             ));
80 80
 
81
-        try {
81
+        try{
82 82
             $this->interceptor->process('foo-job', 'bar', [], $this->core);
83
-        } catch (RetryException $e) {
83
+        }catch (RetryException $e){
84 84
             $this->assertSame(4, $e->getOptions()->getDelay());
85 85
             $this->assertSame(['attempts' => ['1']], $e->getOptions()->getHeaders());
86 86
         }
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
             ->with(self::class, 'bar', [])
112 112
             ->willThrowException(new TestRetryException());
113 113
 
114
-        try {
114
+        try{
115 115
             $this->interceptor->process(self::class, 'bar', [], $this->core);
116
-        } catch (RetryException $e) {
116
+        }catch (RetryException $e){
117 117
             $this->assertSame(1, $e->getOptions()->getDelay());
118 118
             $this->assertSame(['attempts' => ['1']], $e->getOptions()->getHeaders());
119 119
         }
@@ -131,9 +131,9 @@  discard block
 block discarded – undo
131 131
                 retryPolicy: new \Spiral\Queue\RetryPolicy(maxAttempts: 2, delay: 4)
132 132
             ));
133 133
 
134
-        try {
134
+        try{
135 135
             $this->interceptor->process(self::class, 'bar', [], $this->core);
136
-        } catch (RetryException $e) {
136
+        }catch (RetryException $e){
137 137
             $this->assertSame(4, $e->getOptions()->getDelay());
138 138
             $this->assertSame(['attempts' => ['1']], $e->getOptions()->getHeaders());
139 139
         }
@@ -151,14 +151,14 @@  discard block
 block discarded – undo
151 151
             ->with(self::class, 'bar', ['headers' => ['attempts' => ['1']]])
152 152
             ->willThrowException(new TestRetryException());
153 153
 
154
-        try {
154
+        try{
155 155
             $this->interceptor->process(
156 156
                 self::class,
157 157
                 'bar',
158 158
                 ['headers' => ['attempts' => ['1']]],
159 159
                 $this->core
160 160
             );
161
-        } catch (RetryException $e) {
161
+        }catch (RetryException $e){
162 162
             $this->assertSame(8, $e->getOptions()->getDelay());
163 163
             $this->assertSame(['attempts' => ['2']], $e->getOptions()->getHeaders());
164 164
         }
@@ -178,14 +178,14 @@  discard block
 block discarded – undo
178 178
                 retryPolicy: new \Spiral\Queue\RetryPolicy(maxAttempts: 3, delay: 4, multiplier: 2)
179 179
             ));
180 180
 
181
-        try {
181
+        try{
182 182
             $this->interceptor->process(
183 183
                 self::class,
184 184
                 'bar',
185 185
                 ['headers' => ['attempts' => ['1']]],
186 186
                 $this->core
187 187
             );
188
-        } catch (RetryException $e) {
188
+        }catch (RetryException $e){
189 189
             $this->assertSame(8, $e->getOptions()->getDelay());
190 190
             $this->assertSame(['attempts' => ['2']], $e->getOptions()->getHeaders());
191 191
         }
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
             ->method('callAction')
203 203
             ->with(self::class, 'bar', ['headers' => ['attempts' => ['1']]])
204 204
             ->willThrowException(new TestRetryException(
205
-                retryPolicy: new class implements RetryPolicyInterface {
205
+                retryPolicy: new class implements RetryPolicyInterface{
206 206
                     public function isRetryable(\Throwable $exception, int $attempts = 0): bool
207 207
                     {
208 208
                         return true;
@@ -215,14 +215,14 @@  discard block
 block discarded – undo
215 215
                 }
216 216
             ));
217 217
 
218
-        try {
218
+        try{
219 219
             $this->interceptor->process(
220 220
                 self::class,
221 221
                 'bar',
222 222
                 ['headers' => ['attempts' => ['1']]],
223 223
                 $this->core
224 224
             );
225
-        } catch (RetryException $e) {
225
+        }catch (RetryException $e){
226 226
             $this->assertSame(5, $e->getOptions()->getDelay());
227 227
             $this->assertSame(['attempts' => ['2']], $e->getOptions()->getHeaders());
228 228
         }
@@ -244,14 +244,14 @@  discard block
 block discarded – undo
244 244
                 )
245 245
             ));
246 246
 
247
-        try {
247
+        try{
248 248
             $this->interceptor->process(
249 249
                 self::class,
250 250
                 'bar',
251 251
                 ['headers' => ['attempts' => ['1']]],
252 252
                 $this->core
253 253
             );
254
-        } catch (RetryException $e) {
254
+        }catch (RetryException $e){
255 255
             $this->assertSame(8, $e->getOptions()->getDelay());
256 256
             $this->assertSame(['attempts' => ['2']], $e->getOptions()->getHeaders());
257 257
         }
Please login to merge, or discard this patch.
Braces   +37 added lines, -15 removed lines patch added patch discarded remove patch
@@ -78,9 +78,12 @@  discard block
 block discarded – undo
78 78
                 retryPolicy: new \Spiral\Queue\RetryPolicy(maxAttempts: 2, delay: 4)
79 79
             ));
80 80
 
81
-        try {
81
+        try
82
+        {
82 83
             $this->interceptor->process('foo-job', 'bar', [], $this->core);
83
-        } catch (RetryException $e) {
84
+        }
85
+        catch (RetryException $e)
86
+        {
84 87
             $this->assertSame(4, $e->getOptions()->getDelay());
85 88
             $this->assertSame(['attempts' => ['1']], $e->getOptions()->getHeaders());
86 89
         }
@@ -111,9 +114,12 @@  discard block
 block discarded – undo
111 114
             ->with(self::class, 'bar', [])
112 115
             ->willThrowException(new TestRetryException());
113 116
 
114
-        try {
117
+        try
118
+        {
115 119
             $this->interceptor->process(self::class, 'bar', [], $this->core);
116
-        } catch (RetryException $e) {
120
+        }
121
+        catch (RetryException $e)
122
+        {
117 123
             $this->assertSame(1, $e->getOptions()->getDelay());
118 124
             $this->assertSame(['attempts' => ['1']], $e->getOptions()->getHeaders());
119 125
         }
@@ -131,9 +137,12 @@  discard block
 block discarded – undo
131 137
                 retryPolicy: new \Spiral\Queue\RetryPolicy(maxAttempts: 2, delay: 4)
132 138
             ));
133 139
 
134
-        try {
140
+        try
141
+        {
135 142
             $this->interceptor->process(self::class, 'bar', [], $this->core);
136
-        } catch (RetryException $e) {
143
+        }
144
+        catch (RetryException $e)
145
+        {
137 146
             $this->assertSame(4, $e->getOptions()->getDelay());
138 147
             $this->assertSame(['attempts' => ['1']], $e->getOptions()->getHeaders());
139 148
         }
@@ -151,14 +160,17 @@  discard block
 block discarded – undo
151 160
             ->with(self::class, 'bar', ['headers' => ['attempts' => ['1']]])
152 161
             ->willThrowException(new TestRetryException());
153 162
 
154
-        try {
163
+        try
164
+        {
155 165
             $this->interceptor->process(
156 166
                 self::class,
157 167
                 'bar',
158 168
                 ['headers' => ['attempts' => ['1']]],
159 169
                 $this->core
160 170
             );
161
-        } catch (RetryException $e) {
171
+        }
172
+        catch (RetryException $e)
173
+        {
162 174
             $this->assertSame(8, $e->getOptions()->getDelay());
163 175
             $this->assertSame(['attempts' => ['2']], $e->getOptions()->getHeaders());
164 176
         }
@@ -178,14 +190,17 @@  discard block
 block discarded – undo
178 190
                 retryPolicy: new \Spiral\Queue\RetryPolicy(maxAttempts: 3, delay: 4, multiplier: 2)
179 191
             ));
180 192
 
181
-        try {
193
+        try
194
+        {
182 195
             $this->interceptor->process(
183 196
                 self::class,
184 197
                 'bar',
185 198
                 ['headers' => ['attempts' => ['1']]],
186 199
                 $this->core
187 200
             );
188
-        } catch (RetryException $e) {
201
+        }
202
+        catch (RetryException $e)
203
+        {
189 204
             $this->assertSame(8, $e->getOptions()->getDelay());
190 205
             $this->assertSame(['attempts' => ['2']], $e->getOptions()->getHeaders());
191 206
         }
@@ -202,7 +217,8 @@  discard block
 block discarded – undo
202 217
             ->method('callAction')
203 218
             ->with(self::class, 'bar', ['headers' => ['attempts' => ['1']]])
204 219
             ->willThrowException(new TestRetryException(
205
-                retryPolicy: new class implements RetryPolicyInterface {
220
+                retryPolicy: new class implements RetryPolicyInterface
221
+                {
206 222
                     public function isRetryable(\Throwable $exception, int $attempts = 0): bool
207 223
                     {
208 224
                         return true;
@@ -215,14 +231,17 @@  discard block
 block discarded – undo
215 231
                 }
216 232
             ));
217 233
 
218
-        try {
234
+        try
235
+        {
219 236
             $this->interceptor->process(
220 237
                 self::class,
221 238
                 'bar',
222 239
                 ['headers' => ['attempts' => ['1']]],
223 240
                 $this->core
224 241
             );
225
-        } catch (RetryException $e) {
242
+        }
243
+        catch (RetryException $e)
244
+        {
226 245
             $this->assertSame(5, $e->getOptions()->getDelay());
227 246
             $this->assertSame(['attempts' => ['2']], $e->getOptions()->getHeaders());
228 247
         }
@@ -244,14 +263,17 @@  discard block
 block discarded – undo
244 263
                 )
245 264
             ));
246 265
 
247
-        try {
266
+        try
267
+        {
248 268
             $this->interceptor->process(
249 269
                 self::class,
250 270
                 'bar',
251 271
                 ['headers' => ['attempts' => ['1']]],
252 272
                 $this->core
253 273
             );
254
-        } catch (RetryException $e) {
274
+        }
275
+        catch (RetryException $e)
276
+        {
255 277
             $this->assertSame(8, $e->getOptions()->getDelay());
256 278
             $this->assertSame(['attempts' => ['2']], $e->getOptions()->getHeaders());
257 279
         }
Please login to merge, or discard this patch.
src/Queue/src/Interceptor/Consume/RetryPolicyInterceptor.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -18,27 +18,27 @@  discard block
 block discarded – undo
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
             // In some cases job handler class may not exist or be just a string.
30 30
             // In this case we can't get retry policy from it.
31 31
             $class = \class_exists($controller) ? new \ReflectionClass($controller) : null;
32 32
             $policy = $this->getRetryPolicy($e, $class);
33 33
 
34
-            if ($policy === null) {
34
+            if ($policy === null){
35 35
                 throw $e;
36 36
             }
37 37
 
38 38
             $headers = $parameters['headers'] ?? [];
39 39
             $attempts = (int)($headers['attempts'][0] ?? 0);
40 40
 
41
-            if ($policy->isRetryable($e, $attempts) === false) {
41
+            if ($policy->isRetryable($e, $attempts) === false){
42 42
                 throw $e;
43 43
             }
44 44
 
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
             ? $this->reader->firstClassMetadata($handler, Attribute::class)
58 58
             : null;
59 59
 
60
-        if ($exception instanceof JobException && $exception->getPrevious() !== null) {
60
+        if ($exception instanceof JobException && $exception->getPrevious() !== null){
61 61
             $exception = $exception->getPrevious();
62 62
         }
63 63
 
Please login to merge, or discard this patch.
Braces   +11 added lines, -5 removed lines patch added patch discarded remove patch
@@ -23,22 +23,27 @@  discard block
 block discarded – undo
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
             // In some cases job handler class may not exist or be just a string.
30 33
             // In this case we can't get retry policy from it.
31 34
             $class = \class_exists($controller) ? new \ReflectionClass($controller) : null;
32 35
             $policy = $this->getRetryPolicy($e, $class);
33 36
 
34
-            if ($policy === null) {
37
+            if ($policy === null)
38
+            {
35 39
                 throw $e;
36 40
             }
37 41
 
38 42
             $headers = $parameters['headers'] ?? [];
39 43
             $attempts = (int)($headers['attempts'][0] ?? 0);
40 44
 
41
-            if ($policy->isRetryable($e, $attempts) === false) {
45
+            if ($policy->isRetryable($e, $attempts) === false)
46
+            {
42 47
                 throw $e;
43 48
             }
44 49
 
@@ -57,7 +62,8 @@  discard block
 block discarded – undo
57 62
             ? $this->reader->firstClassMetadata($handler, Attribute::class)
58 63
             : null;
59 64
 
60
-        if ($exception instanceof JobException && $exception->getPrevious() !== null) {
65
+        if ($exception instanceof JobException && $exception->getPrevious() !== null)
66
+        {
61 67
             $exception = $exception->getPrevious();
62 68
         }
63 69
 
Please login to merge, or discard this patch.