atymic / twitter

Twitter API for Laravel 5.5+, 6.x, 7.x & 8.x
https://atymic.dev
MIT License
921 stars 290 forks source link

Add support for ratelimit queueing #300

Closed nexxai closed 3 years ago

nexxai commented 4 years ago

Is your feature request related to a problem? Please describe. When managing multiple Twitter accounts with a single application API key, it is likely that you will bump up against Twitter's API rate limits.

Describe the solution you'd like What I envision is some sort of queueing system that would first check the available remaining requests in the 15 minute window (using Twitter::getAppRateLimit()) and then if there are 0 remaining, a job is scheduled for when the count would reset (using that specific API's reset datetime value) and would then execute.

Describe alternatives you've considered I've tried writing my own, but I would still consider myself a novice coder and don't totally understand the logic behind it and so I'm not sure what the best way to do such a thing is.

Additional context n/a

atymic commented 4 years ago

Hmm. Maybe a feature for v3 could be a job middleware for delaying rate limited jobs?

https://laravel.com/docs/7.x/queues#job-middleware

What laravel version are you running?

nexxai commented 4 years ago

This is a completely new app (as of Thursday) so 7.4.0 I believe

atymic commented 3 years ago

I think this is best done in middleware. Unfortunately I don't think we can provide this in the package without dropping support for laravel versions not supporting it.