Passed
Pull Request — master (#980)
by Maxim
27:30 queued 17:33
created
src/Queue/tests/Interceptor/Consume/RetryPolicyInterceptorTest.php 1 patch
Braces   +20 added lines, -8 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,14 +102,17 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
         }
Please login to merge, or discard this patch.
src/Queue/src/RetryPolicy.php 1 patch
Braces   +10 added lines, -5 removed lines patch added patch discarded remove patch
@@ -30,21 +30,24 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 
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,11 +23,15 @@  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
             $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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.