Skip to content
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

[9.x] Make throttle lock acquisition retry time configurable #41516

Conversation

timmartin19
Copy link
Contributor

Depending on context, 750ms can be a long time to wait between retries
for a throttle. We are making the retry time configurable so that users
can tune the throttling further.

All changes are backwards compatible.

I set the unit as milliseconds because this seemed like the natural time
unit to use. Seconds would require floats which felt dirty. That being
said, it's not consistent with the unit used for ->every and ->block
on the builder. So I'm open to changing it for consistency.

I was additionally unsure what useful tests could be written for this
configuration. Mocking the usleep function felt silly. Any suggestions
are welcome.

Redis::throttle('my-key')
    ->allow(5)
    ->every(10)
    ->retryWait(100)
    ->then(static fn () => echo "hello!");

Depending on context, 750ms can be a long time to wait between retries
for a throttle.  We are making the retry time configurable so that users
can tune the throttling further.

All changes are backwards compatible.

I set the unit as milliseconds because this seemed like the natural time
unit to use.  Seconds would require floats which felt dirty.  That being
said, it's not consistent with the unit used for `->every` and `->block`
on the builder.  So I'm open to changing it for consistency.

```php
Redis::throttle('my-key')
    ->allow(5)
    ->every(10)
    ->retryWait(100)
    ->then(static fn () => echo "hello!");
```
@timmartin19 timmartin19 changed the title Make throttle lock acquisition retry time configurable [9.x] Make throttle lock acquisition retry time configurable Mar 16, 2022
@taylorotwell taylorotwell merged commit 0b4f74b into laravel:9.x Mar 16, 2022
@taylorotwell
Copy link
Member

Renamed method to sleep.

@timmartin19 timmartin19 deleted the make-duration-limiter-sleep-time-configurable branch March 16, 2022 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants