Class: ShopifyClient::Throttling::Strategy Abstract
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- ShopifyClient::Throttling::Strategy
- Defined in:
- lib/shopify-client/throttling/strategy.rb
Overview
This class is abstract.
Direct Known Subclasses
Instance Method Summary collapse
-
#after_sleep(env, interval_key) ⇒ Object
Hook for setting the interval key.
- #build_interval_key(env) ⇒ String
-
#interval(interval_key) ⇒ Numeric
Sleep interval in seconds.
- #on_request(env) ⇒ Object
-
#timestamp ⇒ Integer
Time in milliseconds since the UNIX epoch.
Instance Method Details
#after_sleep(env, interval_key) ⇒ Object
Hook for setting the interval key.
38 39 40 |
# File 'lib/shopify-client/throttling/strategy.rb', line 38 def after_sleep(env, interval_key) nil end |
#build_interval_key(env) ⇒ String
19 20 21 22 23 |
# File 'lib/shopify-client/throttling/strategy.rb', line 19 def build_interval_key(env) myshopify_domain = env.dig(:shopify, :myshopify_domain) || 'unknown' format('shopify-client:throttling:%s', myshopify_domain) end |
#interval(interval_key) ⇒ Numeric
Sleep interval in seconds.
30 31 32 |
# File 'lib/shopify-client/throttling/strategy.rb', line 30 def interval(interval_key) 0 end |
#on_request(env) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/shopify-client/throttling/strategy.rb', line 8 def on_request(env) interval_key = build_interval_key(env) sleep(interval(interval_key)) after_sleep(env, interval_key) end |
#timestamp ⇒ Integer
Time in milliseconds since the UNIX epoch.
45 46 47 |
# File 'lib/shopify-client/throttling/strategy.rb', line 45 def (Time.now.to_f * 1000).to_i end |