Module: CMDx::Limiters::FixedWindow Private
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Fixed-window counter using Stores#incr with TTL refresh on each hit.
Instance Method Summary collapse
Instance Method Details
#call(quota) ⇒ RateLimit::Admission
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/cmdx/limiters/fixed_window.rb', line 14 def call(quota) count = Stores.incr(quota.store_key, ttl: quota.per) admitted = count <= quota.max.to_i retry_after = admitted ? nil : Stores.remaining_ttl(quota.store_key) RateLimit::Admission.new( admitted:, count:, level: nil, retry_after:, limiter: :fixed_window ) end |