Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pivotal] Use client-side rate limiting to avoid request throttling
Shortcut's REST API has an advertised rate limit of 200 requests per minute. If 200 or more requests are made within one minute, API clients should expect to receive responses with HTTP status code 429 until enough time has past for the total number of requests made by their API token over the course of the last minute to have dropped below 200. This commit introduces rate limiting on the client (this importer) side, such that users of this pivotal-import tool should never be throttled by Shortcut's API. Since the importer is single-threaded and the rate limiting is handled by an algorithm operating entirely within the Python process' memory, the script should never pause for more than the max_delay set and should never throw an exception related to the rate limit delay being exceeded. It has been configured to throw an exception in case these assumptions do not hold, so that errors are not passed by silently. The rate has been set to 195 requests per minute to keep us comfortably below the rate limit threshold (which is 199 inclusive) without wasting too much possible capacity. The max_delay has been set to 70 seconds to ensure (1) in a case where the max number of requests are made within 1 second, we have a full minute to regain capacity on the Shortcut API side without being throttled by the 200 reqs per minute limit, while also (2) adding a buffer of 10 seconds (1 min == 60 seconds, 60 + 10 == 70 seconds) to account for possible mismatched clock times between the client running this script and the Shortcut API server accepting requests. Co-authored-by: Toby Crawley <[email protected]>
- Loading branch information