-
Notifications
You must be signed in to change notification settings - Fork 2
Integrations
Daniel Pepper edited this page Mar 16, 2022
·
5 revisions
Convert limit errors into a HTTP status code. Use rack-berater or handle it directly:
class ApplicationController < ActionController::Base
around_action :limit
rescue_from Berater::Overloaded { head :too_many_requests }
private
def limit
# limit users to 10 API calls per second
Berater("ingress_limiter:#{user_id}", 10, :second) { yield }
end
end
Sidekiq Ent provides a framework for applying limits to Sidekiq jobs and automatically reschedules workers when limits are exceeded. Berater limiters can be used seamlessly within this framework by registering its error class.
# config/initializers/sidekiq.rb
Sidekiq::Limiter.errors << Berater::Overloaded