Skip to content

Implement linear back-off for Shopify API requests#31

Open
jamiemtdwyer wants to merge 1 commit intoShopify:mainfrom
jamiemtdwyer:api-rate-limit
Open

Implement linear back-off for Shopify API requests#31
jamiemtdwyer wants to merge 1 commit intoShopify:mainfrom
jamiemtdwyer:api-rate-limit

Conversation

@jamiemtdwyer
Copy link

This CI script runs several API requests in sequence and can result in the rate limit being exhausted on the store. This can be quite disruptive to the workflow when validating and merging several PRs against a single store's development (or production) shop.

This PR adds a new parameter, shop_app_api_frequency which represents the frequency at which requests will be made to the Shopify API. The default value is 2, which is the maximum sustained frequency for non-Shopify Plus shops. The frequency can be overridden for Shopify Plus stores by providing a value of 4.

Since we must compute the period (i.e., the amount of time to sleep) by solving (1 / api_frequency), the non-integer math is delegated to bc.

While this rate-limiting behaviour adds a few seconds to the execution time of the script, it prevents the issue of exceeding the rate limit (thus, having to cold boot the whole container and script again which takes a rather long amount of time).

@ghost ghost added the cla-needed label Dec 21, 2021
@jamiemtdwyer
Copy link
Author

jamiemtdwyer commented Dec 21, 2021

I've signed the CLA but my check still failed due to a bad email configuration on my account, is it possible to have it re-run?

@ghost ghost removed the cla-needed label Dec 22, 2021
@jamiemtdwyer
Copy link
Author

Gentle bump :)

return 1
else
# Linear back-off for Shopify API requests
sleep $sleep_time
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this but there's also no loop. Shouldn't there be a loop if you're trying to do a backoff? A retry?

@mattvague
Copy link

Am running into this rate-limiting issue. Anything I can do to help get this across the finish line?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants