nickelser / activejob-traffic_control

Rate limiting/job enabling for ActiveJob using distributed locks in Redis or Memcached.
298 stars 27 forks source link

[Question/Suggestion] Replace instead of drop? #6

Open karl-petter opened 7 years ago

karl-petter commented 7 years ago

Just found this gem and it looks really neat. I'm looking for a possible gem to provide a solution to an issue we recently encountered. Our issue is quite similar to the one mentioned in #4 but slightly different. Let me explain:

One of our systems(our Android/iOS app) reports both some user data and client data(like its current version) with each API call to our main system. We do not have any request limitation on this API so we can receive lots of calls per second. This information is stored in the system on the user model but also reported to another external system. The external system has rate limitation though.

The throttling functionality provided by this gem is perfect to not exceed the rate limit of the external system. Though part of the user data we submit to the external system is the timestamp of the last API request for each user. Therefore we would like to replace any previous queued jobs rather then drop new jobs that are exceeding the rate limit.

I looked through the code briefly to see if something like this could easily be achieved but it does not seem like that. Or do you have any suggestion how this could be achieved with this gem?

In general I think this could be very useful for any kind of REST based API with rate limitation when posting data to that API since one wants the last state transfered and none of the previous ones.