ex_rated icon indicating copy to clipboard operation
ex_rated copied to clipboard

add decrease_remaining_to/4

Open jeremylightsmith opened this issue 3 years ago • 0 comments

When you have several systems, in our case one written in ruby and one in elixir both hitting the same api, they both count against the api's rate limit. In this case, our internal rate limit (maintained w/ ExRated) is occasionally very incorrect.

However, the api returns an x-ratelimit-remaining header. So, if we notice that the api's remaining is much lower than ExRated, we would like to simply use the api's. And we would like to do so atomically, such that, if the value that ExRated has for remaining is actually lower than what the API has, we want to use ExRated's version.

Changes:

  • Adding decrease_remaining_to public function to ExRated, which casts to the genserver
  • It uses select_replace, to get the atomicity (is this performant?)
  • Added tests

jeremylightsmith avatar Jun 18 '22 06:06 jeremylightsmith