Class: ShopifyClient::Throttling::ThreadLocalStrategy
- Inherits:
-
Strategy
- Object
- Faraday::Middleware
- Strategy
- ShopifyClient::Throttling::ThreadLocalStrategy
- Defined in:
- lib/shopify-client/throttling/thread_local_strategy.rb
Overview
Maintain API call limit throttling across a single thread.
Instance Method Summary collapse
- #after_sleep(env, interval_key) ⇒ Object
- #interval(interval_key) ⇒ Object
-
#minimum_interval ⇒ Integer
Minimum time between requests in milliseconds.
Methods inherited from Strategy
#build_interval_key, #on_request, #timestamp
Instance Method Details
#after_sleep(env, interval_key) ⇒ Object
17 18 19 |
# File 'lib/shopify-client/throttling/thread_local_strategy.rb', line 17 def after_sleep(env, interval_key) Thread.current[interval_key] = end |
#interval(interval_key) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/shopify-client/throttling/thread_local_strategy.rb', line 8 def interval(interval_key) return 0 if Thread.current[interval_key].nil? ms = ( - Thread.current[interval_key]) ms < minimum_interval ? Rational(minimum_interval - ms, 1000) : 0 end |
#minimum_interval ⇒ Integer
Minimum time between requests in milliseconds.
24 25 26 |
# File 'lib/shopify-client/throttling/thread_local_strategy.rb', line 24 def minimum_interval 500 end |