Sha256: 0a153be44b6a9be72129aa68dd98d281645c8cc144ba8f776fc366f65f8c6f22
Contents?: true
Size: 1.29 KB
Versions: 1
Compression:
Stored size: 1.29 KB
Contents
ShopifyAPI::Connection.class_eval do alias_method :shopify_request, :request def request(*args) network_retry = 0 network_limit = 10 rate_limit_retry = 0 rate_limit_limit = 30 begin shopify_request(*args) rescue Exception => e exceptions_to_retry = [ ActiveResource::ClientError, Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::EHOSTUNREACH, EOFError, Zlib::BufError, SocketError, ActiveResource::SSLError, # NOTE represents only 500x errors ActiveResource::ServerError ] if !exceptions_to_retry.include?(e.class) raise end if e.class == ActiveResource::ClientError && e.message =~ /429/ && e.message =~ /Too Many Requests/ if rate_limit_retry > 0 && rate_limit_retry % 10 == 0 puts "Shopify Rate Limit Error Encountered" end if rate_limit_retry >= rate_limit_limit raise else rate_limit_retry += 1 sleep(rate_limit_retry) retry end elsif e.class == ActiveResource::ClientError raise end if network_retry >= network_limit raise else network_retry += 1 sleep(network_retry) retry end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
shopify_api_extensions-0.1.2 | lib/shopify_api_extensions/backoff.rb |