Skip to content

A simple Gem for throttling shopify API calls to stay within limits

Notifications You must be signed in to change notification settings

bradrees/shopify-api-throttle

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A simple Gem for throttling shopify API calls to stay within limits

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%