Sha256: b680c77452adb2a629a37923e360b07446920ddd689823269dff9bc045e67c1d
Contents?: true
Size: 1.08 KB
Versions: 1
Compression:
Stored size: 1.08 KB
Contents
module ShopifyApiRateLimiter module ThrottledConnection SHOPIFY_SLEEP_TIME = 0.5 def request(method, path, *arguments) if self === ShopifyAPI::Base.connection if ShopifyAPI::Base.connection.response && ShopifyAPI.credit_maxed? ShopifyApiRateLimiter.logger.info "Shopify rate limit credit maxed. Sleeping #{SHOPIFY_SLEEP_TIME}..." sleep(SHOPIFY_SLEEP_TIME) end begin super rescue ActiveResource::ConnectionError => ex if ex.response.code.to_s == '429' ShopifyApiRateLimiter.logger.info "Shopify returned 429 (Rate Limit Exceeded). Sleeping #{SHOPIFY_SLEEP_TIME}..." sleep(SHOPIFY_SLEEP_TIME) retry else raise ex end rescue ActiveResource::ClientError => e return if e.response.code.to_s == '402' end else super end rescue ShopifyAPI::Limits::LimitUnavailable => limit_unavailable # Either Shopify API stopped sending the limit header, or we're in a stubby test super end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
shopify_api_rate_limiter-0.0.2 | lib/shopify_api_rate_limiter/throttled_connection.rb |