-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[10.x] allow $sleepMilliseconds
parameter receive a Closure in retry
method from PendingRequest
#46653
[10.x] allow $sleepMilliseconds
parameter receive a Closure in retry
method from PendingRequest
#46653
Conversation
$sleepMilliseconds
receive Closure in retry method from PendingRequest
$sleepMilliseconds
receive Closure in retry method from PendingRequest$sleepMilliseconds
parameter receive a Closure in retry
method from PendingRequest
$this->factory->assertSentCount(3); | ||
|
||
// Make sure was waited 300ms for the first two attempts | ||
$this->assertEqualsWithDelta(0.3, microtime(true) - $startTime, 0.03); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could fail in slow machines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know another approach that I can use here to test this? Or maybe it's not necessary test that functionality knowing that is already tested in retry helper scope? Basically I have used the same approach that exists there
Would it be possible to do this on 9.x as well? I don't think there is an issue as the |
Yes, it would. I'll open a PR to implement that there. |
Well, I have opened a PR to make it possible in 9.x, but folks from laravel core said that 9.x is not open for new features, and people needs to upgrade to 10.x. You can see this here |
Well, that's disappointing, but thanks for trying. |
The
retry
helper accepts either anint
or aClosure
. When passing aClosure
object, the$attempts
and the$exception
would be passed, allowed users to implement their own backoff algorithm. Theretry
helper is used in the Pending Request class to perform request retries as well, but in this specific local, the parameters are sent after being informed byretry
method that belongs to the same class mentioned, and in this method, is not accepted to inform$sleepMilliseconds
as aClosure
.This pull request will allows you to inform
$sleepMilliseconds
parameter as aClosure
orint
, opening the possibility to create your own backoff algorithm for retry requests.Example use case
Imagine a scenario where it is necessary to perform a backoff when the exception returned is of type
Request Timeout (408)
, with this modification it would be possible to implement a dynamic strategy as follows: