Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add decrease_remaining_to/4 #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jeremylightsmith
Copy link

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

Copy link
Owner

@grempe grempe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some brief docs to the README to cover usage and motivation for this feature?

I left a note about a typo.

- `id` (Erlang term()) name of the bucket
- `scale` (Integer) of time the bucket you want to inspect was created with.
- `limit` (Integer) representing the max counter size the bucket was created with.
- `new_remaining` (Integer) the new value for remaining, will replace current remaining iff it is less.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a typo in this line "iff"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants