ex_rated
ex_rated copied to clipboard
add decrease_remaining_to/4
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_topublic function to ExRated, which casts to the genserver - It uses select_replace, to get the atomicity (is this performant?)
- Added tests