@nerdware/ddb-single-table
Version:
A schema-based DynamoDB modeling tool, high-level API, and type-generator built to supercharge single-table designs!⚡
34 lines • 2.16 kB
TypeScript
import type { BatchRequestFunction, SomeBatchRequestObject, BatchRetryConfigs } from "./types/index.js";
/**
* This DynamoDB batch-requests helper handles submission and retry logic for batch
* operations like `BatchGetItem` and `BatchWriteItem`.
*
* It works by recursively invoking the provided `submitBatchRequest` function, which
* must return any `UnprocessedItems` or `UnprocessedKeys` from the DDB batch operation.
*
* > To disable the delay between retries, set `initialDelay` to `0`.
*
* ### **Exponential Backoff Strategy:**
*
* 1. First request: no delay
* 2. Second request: delay `initialDelay` milliseconds (default: `100`)
* 3. All subsequent request delays are equal to the previous delay multiplied by the
* `timeMultiplier` (default: `2`), until either:
* - The `maxRetries` limit is reached (default: `10`), or
* - The `maxDelay` limit is reached (default: `3500`, or 3.5 seconds)
*
* Ergo, the base `delay` calculation can be summarized as follows:
* > `initialDelay * timeMultiplier^attemptNumber milliseconds`
*
* If `useJitter` is true (default: `false`), the `delay` is randomized by applying
* the following to the base `delay`: `Math.round(Math.random() * delay)`. Note that
* the determination as to whether the delay exceeds the `maxDelay` is made BEFORE
* jitter is applied.
*
* @param submitBatchRequest A fn which invokes a DDB batch operation and returns any `UnprocessedItems`/`UnprocessedKeys`.
* @param batchRequestObjects The array of request objects to submit via the batch operation.
* @param retryConfigs Configs for the retry strategy.
* @param attemptNumber The current attempt number.
*/
export declare const batchRequestWithExponentialBackoff: <BatchRequestObj extends SomeBatchRequestObject, BatchFn extends BatchRequestFunction<BatchRequestObj> = BatchRequestFunction<BatchRequestObj>>(submitBatchRequest: BatchFn, batchRequestObjects: Array<BatchRequestObj>, retryConfigs?: BatchRetryConfigs, numPreviousRetries?: number) => Promise<Array<BatchRequestObj> | undefined>;
//# sourceMappingURL=batchRequestWithExponentialBackoff.d.ts.map