@@ -97,9 +97,9 @@ discard block |
||
| 97 | 97 | ->with($name, 'bar', []) |
| 98 | 98 | ->willThrowException(new TestRetryException()); |
| 99 | 99 | |
| 100 | - try { |
|
| 100 | + try{ |
|
| 101 | 101 | $this->interceptor->process($name, 'bar', [], $this->core); |
| 102 | - } catch (RetryException $e) { |
|
| 102 | + }catch (RetryException $e){ |
|
| 103 | 103 | $this->assertSame(1, $e->getOptions()->getDelay()); |
| 104 | 104 | $this->assertSame(['attempts' => ['1']], $e->getOptions()->getHeaders()); |
| 105 | 105 | } |
@@ -118,9 +118,9 @@ discard block |
||
| 118 | 118 | retryPolicy: new \Spiral\Queue\RetryPolicy(maxAttempts: 2, delay: 4) |
| 119 | 119 | )); |
| 120 | 120 | |
| 121 | - try { |
|
| 121 | + try{ |
|
| 122 | 122 | $this->interceptor->process($name, 'bar', [], $this->core); |
| 123 | - } catch (RetryException $e) { |
|
| 123 | + }catch (RetryException $e){ |
|
| 124 | 124 | $this->assertSame(4, $e->getOptions()->getDelay()); |
| 125 | 125 | $this->assertSame(['attempts' => ['1']], $e->getOptions()->getHeaders()); |
| 126 | 126 | } |
@@ -139,14 +139,14 @@ discard block |
||
| 139 | 139 | ->with($name, 'bar', ['headers' => ['attempts' => ['1']]]) |
| 140 | 140 | ->willThrowException(new TestRetryException()); |
| 141 | 141 | |
| 142 | - try { |
|
| 142 | + try{ |
|
| 143 | 143 | $this->interceptor->process( |
| 144 | 144 | $name, |
| 145 | 145 | 'bar', |
| 146 | 146 | ['headers' => ['attempts' => ['1']]], |
| 147 | 147 | $this->core |
| 148 | 148 | ); |
| 149 | - } catch (RetryException $e) { |
|
| 149 | + }catch (RetryException $e){ |
|
| 150 | 150 | $this->assertSame(8, $e->getOptions()->getDelay()); |
| 151 | 151 | $this->assertSame(['attempts' => ['2']], $e->getOptions()->getHeaders()); |
| 152 | 152 | } |
@@ -167,14 +167,14 @@ discard block |
||
| 167 | 167 | retryPolicy: new \Spiral\Queue\RetryPolicy(maxAttempts: 3, delay: 4, multiplier: 2) |
| 168 | 168 | )); |
| 169 | 169 | |
| 170 | - try { |
|
| 170 | + try{ |
|
| 171 | 171 | $this->interceptor->process( |
| 172 | 172 | $name, |
| 173 | 173 | 'bar', |
| 174 | 174 | ['headers' => ['attempts' => ['1']]], |
| 175 | 175 | $this->core |
| 176 | 176 | ); |
| 177 | - } catch (RetryException $e) { |
|
| 177 | + }catch (RetryException $e){ |
|
| 178 | 178 | $this->assertSame(8, $e->getOptions()->getDelay()); |
| 179 | 179 | $this->assertSame(['attempts' => ['2']], $e->getOptions()->getHeaders()); |
| 180 | 180 | } |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | ->method('callAction') |
| 193 | 193 | ->with($name, 'bar', ['headers' => ['attempts' => ['1']]]) |
| 194 | 194 | ->willThrowException(new TestRetryException( |
| 195 | - retryPolicy: new class implements RetryPolicyInterface { |
|
| 195 | + retryPolicy: new class implements RetryPolicyInterface{ |
|
| 196 | 196 | public function isRetryable(\Throwable $exception, int $attempts = 0): bool |
| 197 | 197 | { |
| 198 | 198 | return true; |
@@ -205,14 +205,14 @@ discard block |
||
| 205 | 205 | } |
| 206 | 206 | )); |
| 207 | 207 | |
| 208 | - try { |
|
| 208 | + try{ |
|
| 209 | 209 | $this->interceptor->process( |
| 210 | 210 | $name, |
| 211 | 211 | 'bar', |
| 212 | 212 | ['headers' => ['attempts' => ['1']]], |
| 213 | 213 | $this->core |
| 214 | 214 | ); |
| 215 | - } catch (RetryException $e) { |
|
| 215 | + }catch (RetryException $e){ |
|
| 216 | 216 | $this->assertSame(5, $e->getOptions()->getDelay()); |
| 217 | 217 | $this->assertSame(['attempts' => ['2']], $e->getOptions()->getHeaders()); |
| 218 | 218 | } |
@@ -235,14 +235,14 @@ discard block |
||
| 235 | 235 | ) |
| 236 | 236 | )); |
| 237 | 237 | |
| 238 | - try { |
|
| 238 | + try{ |
|
| 239 | 239 | $this->interceptor->process( |
| 240 | 240 | $name, |
| 241 | 241 | 'bar', |
| 242 | 242 | ['headers' => ['attempts' => ['1']]], |
| 243 | 243 | $this->core |
| 244 | 244 | ); |
| 245 | - } catch (RetryException $e) { |
|
| 245 | + }catch (RetryException $e){ |
|
| 246 | 246 | $this->assertSame(8, $e->getOptions()->getDelay()); |
| 247 | 247 | $this->assertSame(['attempts' => ['2']], $e->getOptions()->getHeaders()); |
| 248 | 248 | } |
@@ -97,9 +97,12 @@ discard block |
||
| 97 | 97 | ->with($name, 'bar', []) |
| 98 | 98 | ->willThrowException(new TestRetryException()); |
| 99 | 99 | |
| 100 | - try { |
|
| 100 | + try |
|
| 101 | + { |
|
| 101 | 102 | $this->interceptor->process($name, 'bar', [], $this->core); |
| 102 | - } catch (RetryException $e) { |
|
| 103 | + } |
|
| 104 | + catch (RetryException $e) |
|
| 105 | + { |
|
| 103 | 106 | $this->assertSame(1, $e->getOptions()->getDelay()); |
| 104 | 107 | $this->assertSame(['attempts' => ['1']], $e->getOptions()->getHeaders()); |
| 105 | 108 | } |
@@ -118,9 +121,12 @@ discard block |
||
| 118 | 121 | retryPolicy: new \Spiral\Queue\RetryPolicy(maxAttempts: 2, delay: 4) |
| 119 | 122 | )); |
| 120 | 123 | |
| 121 | - try { |
|
| 124 | + try |
|
| 125 | + { |
|
| 122 | 126 | $this->interceptor->process($name, 'bar', [], $this->core); |
| 123 | - } catch (RetryException $e) { |
|
| 127 | + } |
|
| 128 | + catch (RetryException $e) |
|
| 129 | + { |
|
| 124 | 130 | $this->assertSame(4, $e->getOptions()->getDelay()); |
| 125 | 131 | $this->assertSame(['attempts' => ['1']], $e->getOptions()->getHeaders()); |
| 126 | 132 | } |
@@ -139,14 +145,17 @@ discard block |
||
| 139 | 145 | ->with($name, 'bar', ['headers' => ['attempts' => ['1']]]) |
| 140 | 146 | ->willThrowException(new TestRetryException()); |
| 141 | 147 | |
| 142 | - try { |
|
| 148 | + try |
|
| 149 | + { |
|
| 143 | 150 | $this->interceptor->process( |
| 144 | 151 | $name, |
| 145 | 152 | 'bar', |
| 146 | 153 | ['headers' => ['attempts' => ['1']]], |
| 147 | 154 | $this->core |
| 148 | 155 | ); |
| 149 | - } catch (RetryException $e) { |
|
| 156 | + } |
|
| 157 | + catch (RetryException $e) |
|
| 158 | + { |
|
| 150 | 159 | $this->assertSame(8, $e->getOptions()->getDelay()); |
| 151 | 160 | $this->assertSame(['attempts' => ['2']], $e->getOptions()->getHeaders()); |
| 152 | 161 | } |
@@ -167,14 +176,17 @@ discard block |
||
| 167 | 176 | retryPolicy: new \Spiral\Queue\RetryPolicy(maxAttempts: 3, delay: 4, multiplier: 2) |
| 168 | 177 | )); |
| 169 | 178 | |
| 170 | - try { |
|
| 179 | + try |
|
| 180 | + { |
|
| 171 | 181 | $this->interceptor->process( |
| 172 | 182 | $name, |
| 173 | 183 | 'bar', |
| 174 | 184 | ['headers' => ['attempts' => ['1']]], |
| 175 | 185 | $this->core |
| 176 | 186 | ); |
| 177 | - } catch (RetryException $e) { |
|
| 187 | + } |
|
| 188 | + catch (RetryException $e) |
|
| 189 | + { |
|
| 178 | 190 | $this->assertSame(8, $e->getOptions()->getDelay()); |
| 179 | 191 | $this->assertSame(['attempts' => ['2']], $e->getOptions()->getHeaders()); |
| 180 | 192 | } |
@@ -192,7 +204,8 @@ discard block |
||
| 192 | 204 | ->method('callAction') |
| 193 | 205 | ->with($name, 'bar', ['headers' => ['attempts' => ['1']]]) |
| 194 | 206 | ->willThrowException(new TestRetryException( |
| 195 | - retryPolicy: new class implements RetryPolicyInterface { |
|
| 207 | + retryPolicy: new class implements RetryPolicyInterface |
|
| 208 | + { |
|
| 196 | 209 | public function isRetryable(\Throwable $exception, int $attempts = 0): bool |
| 197 | 210 | { |
| 198 | 211 | return true; |
@@ -205,14 +218,17 @@ discard block |
||
| 205 | 218 | } |
| 206 | 219 | )); |
| 207 | 220 | |
| 208 | - try { |
|
| 221 | + try |
|
| 222 | + { |
|
| 209 | 223 | $this->interceptor->process( |
| 210 | 224 | $name, |
| 211 | 225 | 'bar', |
| 212 | 226 | ['headers' => ['attempts' => ['1']]], |
| 213 | 227 | $this->core |
| 214 | 228 | ); |
| 215 | - } catch (RetryException $e) { |
|
| 229 | + } |
|
| 230 | + catch (RetryException $e) |
|
| 231 | + { |
|
| 216 | 232 | $this->assertSame(5, $e->getOptions()->getDelay()); |
| 217 | 233 | $this->assertSame(['attempts' => ['2']], $e->getOptions()->getHeaders()); |
| 218 | 234 | } |
@@ -235,14 +251,17 @@ discard block |
||
| 235 | 251 | ) |
| 236 | 252 | )); |
| 237 | 253 | |
| 238 | - try { |
|
| 254 | + try |
|
| 255 | + { |
|
| 239 | 256 | $this->interceptor->process( |
| 240 | 257 | $name, |
| 241 | 258 | 'bar', |
| 242 | 259 | ['headers' => ['attempts' => ['1']]], |
| 243 | 260 | $this->core |
| 244 | 261 | ); |
| 245 | - } catch (RetryException $e) { |
|
| 262 | + } |
|
| 263 | + catch (RetryException $e) |
|
| 264 | + { |
|
| 246 | 265 | $this->assertSame(8, $e->getOptions()->getDelay()); |
| 247 | 266 | $this->assertSame(['attempts' => ['2']], $e->getOptions()->getHeaders()); |
| 248 | 267 | } |
@@ -20,28 +20,28 @@ discard block |
||
| 20 | 20 | public function __construct( |
| 21 | 21 | private readonly ReaderInterface $reader, |
| 22 | 22 | private readonly HandlerRegistryInterface $registry, |
| 23 | - ) { |
|
| 23 | + ){ |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | public function process(string $controller, string $action, array $parameters, CoreInterface $core): mixed |
| 27 | 27 | { |
| 28 | - try { |
|
| 28 | + try{ |
|
| 29 | 29 | return $core->callAction($controller, $action, $parameters); |
| 30 | - } catch (\Throwable $e) { |
|
| 31 | - if (!\class_exists($controller)) { |
|
| 30 | + }catch (\Throwable $e){ |
|
| 31 | + if (!\class_exists($controller)){ |
|
| 32 | 32 | $controller = $this->registry->getHandler($controller)::class; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | $policy = $this->getRetryPolicy($e, new \ReflectionClass($controller)); |
| 36 | 36 | |
| 37 | - if ($policy === null) { |
|
| 37 | + if ($policy === null){ |
|
| 38 | 38 | throw $e; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | $headers = $parameters['headers'] ?? []; |
| 42 | 42 | $attempts = (int)($headers['attempts'][0] ?? 0); |
| 43 | 43 | |
| 44 | - if ($policy->isRetryable($e, $attempts) === false) { |
|
| 44 | + if ($policy->isRetryable($e, $attempts) === false){ |
|
| 45 | 45 | throw $e; |
| 46 | 46 | } |
| 47 | 47 | |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | { |
| 59 | 59 | $attribute = $this->reader->firstClassMetadata($handler, Attribute::class); |
| 60 | 60 | |
| 61 | - if ($exception instanceof JobException && $exception->getPrevious() !== null) { |
|
| 61 | + if ($exception instanceof JobException && $exception->getPrevious() !== null){ |
|
| 62 | 62 | $exception = $exception->getPrevious(); |
| 63 | 63 | } |
| 64 | 64 | |
@@ -25,23 +25,29 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | public function process(string $controller, string $action, array $parameters, CoreInterface $core): mixed |
| 27 | 27 | { |
| 28 | - try { |
|
| 28 | + try |
|
| 29 | + { |
|
| 29 | 30 | return $core->callAction($controller, $action, $parameters); |
| 30 | - } catch (\Throwable $e) { |
|
| 31 | - if (!\class_exists($controller)) { |
|
| 31 | + } |
|
| 32 | + catch (\Throwable $e) |
|
| 33 | + { |
|
| 34 | + if (!\class_exists($controller)) |
|
| 35 | + { |
|
| 32 | 36 | $controller = $this->registry->getHandler($controller)::class; |
| 33 | 37 | } |
| 34 | 38 | |
| 35 | 39 | $policy = $this->getRetryPolicy($e, new \ReflectionClass($controller)); |
| 36 | 40 | |
| 37 | - if ($policy === null) { |
|
| 41 | + if ($policy === null) |
|
| 42 | + { |
|
| 38 | 43 | throw $e; |
| 39 | 44 | } |
| 40 | 45 | |
| 41 | 46 | $headers = $parameters['headers'] ?? []; |
| 42 | 47 | $attempts = (int)($headers['attempts'][0] ?? 0); |
| 43 | 48 | |
| 44 | - if ($policy->isRetryable($e, $attempts) === false) { |
|
| 49 | + if ($policy->isRetryable($e, $attempts) === false) |
|
| 50 | + { |
|
| 45 | 51 | throw $e; |
| 46 | 52 | } |
| 47 | 53 | |
@@ -58,7 +64,8 @@ discard block |
||
| 58 | 64 | { |
| 59 | 65 | $attribute = $this->reader->firstClassMetadata($handler, Attribute::class); |
| 60 | 66 | |
| 61 | - if ($exception instanceof JobException && $exception->getPrevious() !== null) { |
|
| 67 | + if ($exception instanceof JobException && $exception->getPrevious() !== null) |
|
| 68 | + { |
|
| 62 | 69 | $exception = $exception->getPrevious(); |
| 63 | 70 | } |
| 64 | 71 | |