Rate limit plugin #52
Replies: 11 comments 1 reply
-
|
Yes, this would be great! I wonder if community made plugins could be released as standalone packages. Is this something you would be up for building? |
Beta Was this translation helpful? Give feedback.
-
|
This would be a useful plugin for me, so I could mantain it, what do you think? |
Beta Was this translation helpful? Give feedback.
-
|
If you are happy to, I would add it to a list of community driven plugins for Saloon. |
Beta Was this translation helpful? Give feedback.
-
|
Just a suggestion, it would be cool if the plugin also added two methods to "set" and "get" from a cache, so it would be really easy for Laravel users to hook it up to their Laravel app's cache |
Beta Was this translation helpful? Give feedback.
-
|
I'll probably do something simple, and expose the API for the user to customize as needed. |
Beta Was this translation helpful? Give feedback.
-
|
Sounds good. Looking forward to seeing it. |
Beta Was this translation helpful? Give feedback.
-
|
Just a thought, I need a rate limiter in Laravel, but I'd probably prefer if it threw an exception that I can catch in my job and delay it by X amount of seconds that the API replies with. Maybe that's something to consider in another plugin? Like a back-off plugin that uses Laravel Cache to determine if a rate limit has been exceeded |
Beta Was this translation helpful? Give feedback.
-
|
Hi, I'm still on it, I'll be back soon with news. |
Beta Was this translation helpful? Give feedback.
-
|
Sounds good @yurirnascimento no pressure on my side, take your time. Looking forward to seeing it. |
Beta Was this translation helpful? Give feedback.
-
|
I saw this online and thought it was really cool, perhaps we could use it for Saloon's rate limit plugin... |
Beta Was this translation helpful? Give feedback.
-
|
Hey @yurirnascimento Just wanted to let you know that I have been working on a new rate-limiting plugin for Saloon and I'm really excited about how it works. Would love to get your ideas/feedback on what I have built so far. The goal with the new plugin is to act on prevention rather than reaction, so it's supposed to record the number of requests that you have made on a connector, and then if you have reached the number of requests within a given threshold, it will throw an exception or sleep/wait until the rate limit has lifted. You first define the limits on your connector, as well as the rate limit store. The plugin will come with redis, predis, file, and PSR cache stores. You can have multiple limits too with lots of different intervals. // In your connector
protected function resolveLimits(): array
{
return [
Limit::allow(100)->perMinute(),
Limit::allow(1000)->perDay(),
Limit::allow(10000)->perWeek()->name('custom-name'),
Limit::fromTooManyRequests(retry: 60), // This one will stop all future requests if a response is 429
];
}Next when you make requests, we will keep track of the number of hits per-limit and record it in the stores. When it comes to Laravel queued jobs, you'll be able to check if there are any limits before making requests, for example at the top of your job, you could write something like: public function handle()
{
if ($limit = $this->connector->getExceededLimit()) {
$this->release($limit->getRemainingSeconds()); // Release job back onto queue to wait for the limit to be released
}
}Check out the source code here: https://github.com/Sammyjo20/saloon-rate-limiter-plugin I'm still working on the tests and getting it working, but would love to hear if I've missed anything. |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
One of my needs is to be able to use a request rate limit, because normally my jobs run for long periods but need to respect the API's request limit.
I'm creating a plugin to use the Spatie/GuzzleRateLimiterMIddleware
Would it be useful to anyone else?
Beta Was this translation helpful? Give feedback.
All reactions