import { TaskFailureDetails } from "../failure-details"; /** * Type for a predicate function that determines whether a failure should be retried. * Receives the failure details and returns true to retry, false to stop. */ export type FailureHandlerPredicate = (failure: TaskFailureDetails) => boolean; /** * A declarative retry policy that can be configured for activity or sub-orchestration calls. * * @remarks * Retry policies control how many times a task is retried and the delay between retries. * The delay between retries increases exponentially based on the backoffCoefficient. * * @example * ```typescript * const retryPolicy = new RetryPolicy({ * maxNumberOfAttempts: 5, * firstRetryIntervalInMilliseconds: 1000, * backoffCoefficient: 2.0, * maxRetryIntervalInMilliseconds: 30000, * retryTimeoutInMilliseconds: 300000 * }); * ``` * * @example * ```typescript * // With handleFailure predicate to filter which errors to retry * const retryPolicy = new RetryPolicy({ * maxNumberOfAttempts: 3, * firstRetryIntervalInMilliseconds: 1000, * handleFailure: (failure) => { * // Only retry transient errors, not validation errors * return failure.errorType !== "ValidationError"; * } * }); * ``` */ export declare class RetryPolicy { private readonly _maxNumberOfAttempts; private readonly _firstRetryIntervalInMilliseconds; private readonly _backoffCoefficient; private readonly _maxRetryIntervalInMilliseconds; private readonly _retryTimeoutInMilliseconds; private readonly _handleFailure; /** * Creates a new RetryPolicy instance. * * @param options - The retry policy options * @throws Error if any of the validation constraints are violated */ constructor(options: RetryPolicyOptions); /** * Gets the max number of attempts for executing a given task. */ get maxNumberOfAttempts(): number; /** * Gets the amount of time in milliseconds to delay between the first and second attempt. */ get firstRetryIntervalInMilliseconds(): number; /** * Gets the exponential back-off coefficient used to determine the delay between subsequent retries. * @remarks Defaults to 1.0 for no back-off. */ get backoffCoefficient(): number; /** * Gets the maximum time in milliseconds to delay between attempts. * @remarks Defaults to 1 hour (3600000ms). Use -1 for infinite. */ get maxRetryIntervalInMilliseconds(): number; /** * Gets the overall timeout for retries in milliseconds. * No further attempts will be made after this timeout expires. * @remarks Defaults to -1 (infinite). */ get retryTimeoutInMilliseconds(): number; /** * Gets the predicate function that determines whether a specific failure should be retried. * * @remarks * This predicate is called for each failure to determine if a retry should be attempted. * Even if this predicate allows a retry, time-based and attempt-count constraints may still * prevent another attempt from being scheduled. * Defaults to a function that always returns true (all failures are retried). * * @returns A function that takes TaskFailureDetails and returns true to retry, false to stop. */ get handleFailure(): FailureHandlerPredicate; /** * Evaluates whether a failure should be retried based on the handleFailure predicate. * * @param failure - The failure details to evaluate * @returns true if the failure should be retried, false otherwise */ shouldRetry(failure: TaskFailureDetails): boolean; } /** * Options for creating a RetryPolicy. */ export interface RetryPolicyOptions { /** * The maximum number of task invocation attempts. Must be 1 or greater. */ maxNumberOfAttempts: number; /** * The amount of time in milliseconds to delay between the first and second attempt. * Must be greater than 0. */ firstRetryIntervalInMilliseconds: number; /** * The exponential back-off coefficient used to determine the delay between subsequent retries. * Must be 1.0 or greater. * @default 1.0 */ backoffCoefficient?: number; /** * The maximum time in milliseconds to delay between attempts. * Must be greater than or equal to firstRetryIntervalInMilliseconds. * Use -1 for infinite (no maximum). * @default 3600000 (1 hour) */ maxRetryIntervalInMilliseconds?: number; /** * The overall timeout for retries in milliseconds. * No further attempts will be made after this timeout expires. * Use -1 for infinite (no timeout). * @default -1 (infinite) */ retryTimeoutInMilliseconds?: number; /** * Optional predicate to determine if a specific failure should be retried. * * @remarks * This predicate receives TaskFailureDetails and should return true to retry * or false to stop retrying. The predicate is evaluated first to enable fail-fast * behavior for non-retriable errors, but any retry that it allows is still subject * to the overall time and attempt count constraints of this policy. * * @default A function that always returns true (all failures are retried) * * @example * ```typescript * const policy = new RetryPolicy({ * maxNumberOfAttempts: 5, * firstRetryIntervalInMilliseconds: 1000, * handleFailure: (failure) => { * // Don't retry validation errors * if (failure.errorType === "ValidationError") { * return false; * } * // Retry all other errors * return true; * } * }); * ``` */ handleFailure?: FailureHandlerPredicate; }