Passed
Push — master ( 093622...13cd72 )
by butschster
06:20 queued 19s
created
src/Queue/tests/Interceptor/Consume/RetryPolicyInterceptorTest.php 1 patch
Braces   +25 added lines, -10 removed lines patch added patch discarded remove patch
@@ -79,9 +79,12 @@  discard block
 block discarded – undo
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,9 +102,12 @@  discard block
 block discarded – undo
99 102
                 retryPolicy: new \Spiral\Queue\RetryPolicy(maxAttempts: 2, delay: 4)
100 103
             ));
101 104
 
102
-        try {
105
+        try
106
+        {
103 107
             $this->interceptor->process(self::class, 'bar', [], $this->core);
104
-        } catch (RetryException $e) {
108
+        }
109
+        catch (RetryException $e)
110
+        {
105 111
             $this->assertSame(4, $e->getOptions()->getDelay());
106 112
             $this->assertSame(['attempts' => ['1']], $e->getOptions()->getHeaders());
107 113
         }
@@ -119,14 +125,17 @@  discard block
 block discarded – undo
119 125
             ->with(self::class, 'bar', ['headers' => ['attempts' => ['1']]])
120 126
             ->willThrowException(new TestRetryException());
121 127
 
122
-        try {
128
+        try
129
+        {
123 130
             $this->interceptor->process(
124 131
                 self::class,
125 132
                 'bar',
126 133
                 ['headers' => ['attempts' => ['1']]],
127 134
                 $this->core
128 135
             );
129
-        } catch (RetryException $e) {
136
+        }
137
+        catch (RetryException $e)
138
+        {
130 139
             $this->assertSame(8, $e->getOptions()->getDelay());
131 140
             $this->assertSame(['attempts' => ['2']], $e->getOptions()->getHeaders());
132 141
         }
@@ -146,14 +155,17 @@  discard block
 block discarded – undo
146 155
                 retryPolicy: new \Spiral\Queue\RetryPolicy(maxAttempts: 3, delay: 4, multiplier: 2)
147 156
             ));
148 157
 
149
-        try {
158
+        try
159
+        {
150 160
             $this->interceptor->process(
151 161
                 self::class,
152 162
                 'bar',
153 163
                 ['headers' => ['attempts' => ['1']]],
154 164
                 $this->core
155 165
             );
156
-        } catch (RetryException $e) {
166
+        }
167
+        catch (RetryException $e)
168
+        {
157 169
             $this->assertSame(8, $e->getOptions()->getDelay());
158 170
             $this->assertSame(['attempts' => ['2']], $e->getOptions()->getHeaders());
159 171
         }
@@ -175,14 +187,17 @@  discard block
 block discarded – undo
175 187
                 )
176 188
             ));
177 189
 
178
-        try {
190
+        try
191
+        {
179 192
             $this->interceptor->process(
180 193
                 self::class,
181 194
                 'bar',
182 195
                 ['headers' => ['attempts' => ['1']]],
183 196
                 $this->core
184 197
             );
185
-        } catch (RetryException $e) {
198
+        }
199
+        catch (RetryException $e)
200
+        {
186 201
             $this->assertSame(8, $e->getOptions()->getDelay());
187 202
             $this->assertSame(['attempts' => ['2']], $e->getOptions()->getHeaders());
188 203
         }
Please login to merge, or discard this patch.
src/Queue/src/Interceptor/Consume/RetryPolicyInterceptor.php 1 patch
Braces   +11 added lines, -5 removed lines patch added patch discarded remove patch
@@ -23,19 +23,24 @@  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
             $policy = $this->getRetryPolicy($e, new \ReflectionClass($controller));
30 33
 
31
-            if ($policy === null) {
34
+            if ($policy === null)
35
+            {
32 36
                 throw $e;
33 37
             }
34 38
 
35 39
             $headers = $parameters['headers'] ?? [];
36 40
             $attempts = (int)($headers['attempts'][0] ?? 0);
37 41
 
38
-            if ($policy->isRetryable($e, $attempts) === false) {
42
+            if ($policy->isRetryable($e, $attempts) === false)
43
+            {
39 44
                 throw $e;
40 45
             }
41 46
 
@@ -52,7 +57,8 @@  discard block
 block discarded – undo
52 57
     {
53 58
         $attribute = $this->reader->firstClassMetadata($handler, Attribute::class);
54 59
 
55
-        if ($exception instanceof JobException && $exception->getPrevious() !== null) {
60
+        if ($exception instanceof JobException && $exception->getPrevious() !== null)
61
+        {
56 62
             $exception = $exception->getPrevious();
57 63
         }
58 64
 
Please login to merge, or discard this patch.