UNPKG

@temporalio/client

Version:
59 lines (58 loc) 1.99 kB
import { Interceptor, StatusObject } from '@grpc/grpc-js'; export interface GrpcRetryOptions { /** * A function which accepts the current retry attempt (starts at 1) and returns the millisecond * delay that should be applied before the next retry. */ delayFunction: (attempt: number, status: StatusObject) => number; /** * A function which accepts a failed status object and returns true if the call should be retried */ retryableDecider: (attempt: number, status: StatusObject) => boolean; } /** * Options for the backoff formula: `factor ^ attempt * initialIntervalMs(status) * jitter(maxJitter)` */ export interface BackoffOptions { /** * Exponential backoff factor * * @default 1.7 */ factor: number; /** * Maximum number of attempts * * @default 10 */ maxAttempts: number; /** * Maximum amount of jitter to apply * * @default 0.2 */ maxJitter: number; /** * Function that returns the "initial" backoff interval based on the returned status. * * The default is 1 second for RESOURCE_EXHAUSTED errors and 100 millis for other retryable errors. */ initialIntervalMs(status: StatusObject): number; /** * Function that returns the "maximum" backoff interval based on the returned status. * * The default is 5 seconds regardless of the status. */ maxIntervalMs(status: StatusObject): number; } /** * Generates the default retry behavior based on given backoff options */ export declare function defaultGrpcRetryOptions(options?: Partial<BackoffOptions>): GrpcRetryOptions; export declare function isRetryableError(status: StatusObject): boolean; /** * Returns a GRPC interceptor that will perform automatic retries for some types of failed calls * * @param retryOptions Options for the retry interceptor */ export declare function makeGrpcRetryInterceptor(retryOptions: GrpcRetryOptions): Interceptor;