UNPKG

deepsource-mcp-server

Version:
79 lines (78 loc) 2.57 kB
/** * @fileoverview Retry executor that combines all retry components * This module orchestrates retry logic using policies, backoff, circuit breakers, and budgets. */ import { RetryPolicy } from './retry-policy.js'; /** * Context information for retry execution * @interface * @public */ export interface RetryContext { /** The endpoint or operation being retried */ endpoint: string; /** The attempt number (0-indexed) */ attemptNumber: number; /** Total elapsed time since first attempt */ elapsedMs: number; /** The last error encountered */ lastError?: unknown; /** Whether this is the last attempt */ isLastAttempt: boolean; } /** * Result of a retry execution * @interface * @public */ export interface RetryResult<T> { /** Whether the operation succeeded */ success: boolean; /** The result data if successful */ data?: T; /** The final error if unsuccessful */ error?: unknown; /** Number of attempts made */ attempts: number; /** Total time taken for all attempts */ totalDurationMs: number; /** Whether retry was blocked by circuit breaker */ circuitBreakerBlocked: boolean; /** Whether retry was blocked by budget exhaustion */ budgetExhausted: boolean; } /** * Options for retry execution * @interface * @public */ export interface RetryExecutorOptions { /** Override the default retry policy */ policy?: RetryPolicy; /** Custom endpoint name for circuit breaker and budget */ endpoint?: string; /** Callback for each retry attempt */ onRetryAttempt?: (context: RetryContext) => void; /** Maximum total duration for all retries (ms) */ maxTotalDuration?: number; /** Function to extract Retry-After header from error */ extractRetryAfter?: (error: unknown) => string | undefined; } /** * Execute a function with automatic retry logic * @template T The return type of the function * @param fn The function to execute * @param options Retry execution options * @returns The result of the execution * @public */ export declare function executeWithRetry<T>(fn: () => Promise<T>, options?: RetryExecutorOptions): Promise<RetryResult<T>>; /** * Create a retry-enabled wrapper for a function * @template T The return type of the function * @param fn The function to wrap * @param options Default retry options for the wrapper * @returns A retry-enabled version of the function * @public */ export declare function withRetry<T>(fn: () => Promise<T>, options?: RetryExecutorOptions): () => Promise<T>;