Skip to content

Latest commit

 

History

History
33 lines (19 loc) · 1.01 KB

README.rdoc

File metadata and controls

33 lines (19 loc) · 1.01 KB

shopify-api-throttle

This is a gem for dealing with the API limits placed on the Shopify API.

Problem

Currently Shopify a leaky bucket limiter when using the API, if you go over that limit it will throw an exception.

Solution

By wrapping all the calls in a throttling method it is possible to wait until the API limit is reset or retry failing calls.

Installation

gem "shopify_api"
gem "shopify-api-throttle"

Usage

Background workers will want to ensure that all of their calls are completed, even if that results in some delays in processing. To handle this a new method has been added that executes a block.

ShopifyAPI.throttle { shopifyObject.save! }

Remember scoping issues also apply:

collection = nil
ShopifyAPI.throttle { collection = ShopifyAPI::CustomCollection.find(123) }

Or much easier

collection = ShopifyAPI.throttle { ShopifyAPI::CustomCollection.find(123) }

The block will be retried up to a number times, and will sleep for an increasing number of seconds between retries.