Class: ShopifyClient::Throttling::ThreadLocalStrategy

Inherits:
Strategy
  • Object
show all
Defined in:
lib/shopify-client/throttling/thread_local_strategy.rb

Overview

Maintain API call limit throttling across a single thread.

Instance Method Summary collapse

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] = timestamp
end

#interval(interval_key) ⇒ Object

See Also:



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 = (timestamp - Thread.current[interval_key])

  ms < minimum_interval ? Rational(minimum_interval - ms, 1000) : 0
end

#minimum_intervalInteger

Minimum time between requests in milliseconds.

Returns:

  • (Integer)


24
25
26
# File 'lib/shopify-client/throttling/thread_local_strategy.rb', line 24

def minimum_interval
  500
end