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

Expose a way to determine if the rate limit is already hit? #5

Open
ishields opened this issue Jan 28, 2023 · 1 comment
Open

Expose a way to determine if the rate limit is already hit? #5

ishields opened this issue Jan 28, 2023 · 1 comment

Comments

@ishields
Copy link

If this exists already perhaps you can help me identify how to do it. I'm looking for a way to detect whether a particular key will overflow in the next call. Digging into the source it looks like it would be using this method
within_rate_limit? but would need to not increment the counter

def next_within_rate_limit?
      ExcessFlow::GlobalMutex.locked(lock_key: configuration.lock_key) do
        cleanup_stale_counters

        if current_requests < configuration.limit
          true
        else
          false
        end
      end
    end
end

The big difference is it wouldn't call the "bump_counter" method.

@ishields
Copy link
Author

ishields commented Jan 28, 2023

I was able to produce this behavior with something like this but would love to know if it's the recommended way.

    ExcessFlow.redis { |r| r.get(ExcessFlow::ThrottleConfiguration.new({ key: name.to_s, limit: rate, ttl: interval }).counter_key) }.to_i

Seems like a nice helper method would be a useful addition.

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

No branches or pull requests

1 participant