UNPKG

1.93 kBTypeScriptView Raw
1import { SdkError } from "@aws-sdk/types";
2/**
3 * Determines whether an error is retryable based on the number of retries
4 * already attempted, the HTTP status code, and the error received (if any).
5 *
6 * @param error The error encountered.
7 */
8export interface RetryDecider {
9 (error: SdkError): boolean;
10}
11/**
12 * Determines the number of milliseconds to wait before retrying an action.
13 *
14 * @param delayBase The base delay (in milliseconds).
15 * @param attempts The number of times the action has already been tried.
16 */
17export interface DelayDecider {
18 (delayBase: number, attempts: number): number;
19}
20/**
21 * Interface that specifies the retry quota behavior.
22 */
23export interface RetryQuota {
24 /**
25 * returns true if retry tokens are available from the retry quota bucket.
26 */
27 hasRetryTokens: (error: SdkError) => boolean;
28 /**
29 * returns token amount from the retry quota bucket.
30 * throws error is retry tokens are not available.
31 */
32 retrieveRetryTokens: (error: SdkError) => number;
33 /**
34 * releases tokens back to the retry quota.
35 */
36 releaseRetryTokens: (releaseCapacityAmount?: number) => void;
37}
38export interface RateLimiter {
39 /**
40 * If there is sufficient capacity (tokens) available, it immediately returns.
41 * If there is not sufficient capacity, it will either sleep a certain amount
42 * of time until the rate limiter can retrieve a token from its token bucket
43 * or raise an exception indicating there is insufficient capacity.
44 */
45 getSendToken: () => Promise<void>;
46 /**
47 * Updates the client sending rate based on response.
48 * If the response was successful, the capacity and fill rate are increased.
49 * If the response was a throttling response, the capacity and fill rate are
50 * decreased. Transient errors do not affect the rate limiter.
51 */
52 updateClientSendingRate: (response: any) => void;
53}