Class: Hudu::RateThrottleMiddleware
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Hudu::RateThrottleMiddleware
- Defined in:
- lib/hudu/rate_throttle_middleware.rb
Overview
A Faraday middleware for rate limiting requests.
This middleware ensures that the number of requests made through a Faraday connection does not exceed a specified limit within a given time period.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, limit: 300, period: 60) ⇒ RateThrottleMiddleware
constructor
Initializes the RateThrottleMiddleware.
Constructor Details
#initialize(app, limit: 300, period: 60) ⇒ RateThrottleMiddleware
Initializes the RateThrottleMiddleware.
29 30 31 32 33 34 35 36 |
# File 'lib/hudu/rate_throttle_middleware.rb', line 29 def initialize(app, limit: 300, period: 60) super(app) @limit = limit @period = period @requests = [] @mutex = Mutex.new @condition = ConditionVariable.new end |
Instance Method Details
#call(env) ⇒ Object
38 39 40 41 |
# File 'lib/hudu/rate_throttle_middleware.rb', line 38 def call(env) throttle_request @app.call(env) end |