tdpw
Version:
CLI tool for uploading Playwright test reports to TestDino platform with Azure storage support
52 lines • 1.87 kB
TypeScript
/**
* Retry utility with exponential backoff and circuit breaker
* Handles network failures and temporary service unavailability
*/
/**
* Configuration options for retry behavior
*/
export interface RetryOptions {
/** Maximum number of attempts (default: 3) */
maxAttempts?: number;
/** Base delay in milliseconds (default: 1000) */
baseDelay?: number;
/** Maximum delay in milliseconds (default: 30000) */
maxDelay?: number;
/** Backoff factor (default: 2) */
factor?: number;
/** Timeout per attempt in milliseconds (default: 120000 = 2 minutes) */
timeout?: number;
/** Function to determine if error should trigger retry */
shouldRetry?: (error: Error) => boolean;
}
/**
* Execute an operation with retry logic and exponential backoff
*/
export declare function withRetry<T>(operation: () => Promise<T>, options?: RetryOptions): Promise<T>;
/**
* Specialized retry for file upload operations
* Uses different retry logic optimized for large file uploads
*/
export declare function withFileUploadRetry<T>(operation: () => Promise<T>, _fileName?: string): Promise<T>;
/**
* Circuit breaker pattern for external service calls
* Prevents cascading failures when external services are down
*/
export declare class CircuitBreaker<T> {
private readonly operation;
private readonly options;
private failureCount;
private lastFailureTime;
private isOpen;
constructor(operation: () => Promise<T>, options: {
failureThreshold: number;
resetTimeout: number;
monitor?: (state: 'closed' | 'open' | 'half-open') => void;
});
execute(): Promise<T>;
}
/**
* Helper to create a circuit breaker for API calls
*/
export declare function createApiCircuitBreaker<T>(operation: () => Promise<T>, serviceName: string): CircuitBreaker<T>;
//# sourceMappingURL=retry.d.ts.map