Class: ShopifyClient::Throttling::Strategy Abstract

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/shopify-client/throttling/strategy.rb

Overview

This class is abstract.

Direct Known Subclasses

RedisStrategy, ThreadLocalStrategy

Instance Method Summary collapse

Instance Method Details

#after_sleep(env, interval_key) ⇒ Object

Hook for setting the interval key.

Parameters:

  • env (Faraday::Env)
  • interval_key (String)


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

Parameters:

  • env (Faraday::Env)

Returns:

  • (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.

Parameters:

  • interval_key (String)

Returns:

  • (Numeric)


30
31
32
# File 'lib/shopify-client/throttling/strategy.rb', line 30

def interval(interval_key)
  0
end

#on_request(env) ⇒ Object

Parameters:

  • env (Faraday::Env)


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

#timestampInteger

Time in milliseconds since the UNIX epoch.

Returns:

  • (Integer)


45
46
47
# File 'lib/shopify-client/throttling/strategy.rb', line 45

def timestamp
  (Time.now.to_f * 1000).to_i
end