Implement linear back-off for Shopify API requests #31
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 of4
.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 tobc
.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).