You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If successful `$result` will contain the result of the closure. If max attempts are exceeded the inner exception is re-thrown.
32
32
33
-
You can of course provide other options via the helper method if needed.
33
+
You can of course provide other options via the helper method if needed.
34
34
35
35
Method parameters are `$callback`, `$maxAttempts`, `$strategy`, `$waitCap`, `$useJitter`.
36
36
37
37
## Backoff class usage
38
-
38
+
39
39
The Backoff class constructor parameters are `$maxAttempts`, `$strategy`, `$waitCap`, `$useJitter`.
40
40
41
41
```
@@ -156,7 +156,7 @@ Finally, you can pass in a closure as the strategy if you wish. This closure sho
156
156
backoff(function() {
157
157
...
158
158
}, 10, function($attempt) {
159
-
return (100 * $attempt) + 5000;
159
+
return (100 * $attempt) + 5000;
160
160
});
161
161
162
162
// OR
@@ -176,11 +176,25 @@ This cap can be provided as the fourth argument to the `backoff` helper function
176
176
## Jitter
177
177
178
178
If you have a lot of clients starting a job at the same time and encountering failures, any of the above backoff strategies could mean the workers continue to collide at each retry.
179
-
179
+
180
180
The solution for this is to add randomness. See here for a good explanation:
You can enable jitter by passing `true` in as the fifth argument to the `backoff` helper function, or by using the `enableJitter()` method on the Backoff class.
185
-
185
+
186
186
We use the "FullJitter" approach outlined in the above article, where a random number between 0 and the sleep time provided by your selected strategy is used.
187
+
188
+
## Custom retry decider
189
+
190
+
By default Backoff will retry if an exception is encountered, and if it has not yet hit max retries.
191
+
192
+
You may provide your own retry decider for more advanced use cases. Perhaps you want to retry based on time rather than number of retries, or perhaps there are scenarios where you would want retry even when an exception was not encountered.
193
+
194
+
Provide the decider as a callback, or an instance of a class with an `__invoke` method. Backoff will hand it four parameters: the current attempt, max attempts, the last result received, and the exception if one was encountered. Your decider needs to return true or false.
0 commit comments