UNPKG

@re-shell/cli

Version:

Full-stack development platform uniting microservices and microfrontends. Build complete applications with .NET (ASP.NET Core Web API, Minimal API), Java (Spring Boot, Quarkus, Micronaut, Vert.x), Rust (Actix-Web, Warp, Rocket, Axum), Python (FastAPI, Dja

114 lines (113 loc) 4.01 kB
import { EventEmitter } from 'events'; export interface RetryOptions { maxAttempts: number; baseDelay: number; maxDelay: number; backoffMultiplier: number; jitter: boolean; timeout?: number; retryCondition?: (error: any) => boolean; onRetry?: (attempt: number, error: any, delay: number) => void; } export interface CircuitBreakerOptions { failureThreshold: number; recoveryTimeout: number; monitoringPeriod: number; volumeThreshold: number; errorThresholdPercentage: number; onStateChange?: (state: CircuitState) => void; } export declare enum CircuitState { CLOSED = "closed", OPEN = "open", HALF_OPEN = "half-open" } export interface RetryResult<T> { success: boolean; result?: T; error?: Error; attempts: number; totalDuration: number; lastAttemptDuration: number; } export interface CircuitBreakerStats { state: CircuitState; failureCount: number; successCount: number; totalCalls: number; failureRate: number; lastFailureTime?: Date; lastSuccessTime?: Date; nextRetryTime?: Date; } export declare class RetryExecutor extends EventEmitter { private options; private defaultOptions; constructor(options?: Partial<RetryOptions>); execute<T>(operation: () => Promise<T>, customOptions?: Partial<RetryOptions>): Promise<RetryResult<T>>; private calculateDelay; private withTimeout; private sleep; static withRetry<T>(operation: () => Promise<T>, options?: Partial<RetryOptions>): Promise<T>; static isRetryableError(error: any): boolean; } export declare class CircuitBreaker extends EventEmitter { private name; private options; private state; private failureCount; private successCount; private totalCalls; private lastFailureTime?; private lastSuccessTime?; private nextRetryTime?; private stats; private defaultOptions; constructor(name: string, options?: Partial<CircuitBreakerOptions>); execute<T>(operation: () => Promise<T>): Promise<T>; private onSuccess; private onFailure; private shouldTrip; private shouldAttemptReset; private setNextRetryTime; private setState; private startMonitoring; private resetCounters; getStats(): CircuitBreakerStats; reset(): void; forceOpen(): void; forceClose(): void; getName(): string; getState(): CircuitState; isOpen(): boolean; isClosed(): boolean; isHalfOpen(): boolean; } export declare class RetryManager extends EventEmitter { private retryExecutors; private circuitBreakers; createRetryExecutor(name: string, options?: Partial<RetryOptions>): RetryExecutor; createCircuitBreaker(name: string, options?: Partial<CircuitBreakerOptions>): CircuitBreaker; executeWithRetryAndCircuitBreaker<T>(name: string, operation: () => Promise<T>, retryOptions?: Partial<RetryOptions>, circuitOptions?: Partial<CircuitBreakerOptions>): Promise<T>; getRetryExecutor(name: string): RetryExecutor | undefined; getCircuitBreaker(name: string): CircuitBreaker | undefined; getAllCircuitBreakers(): CircuitBreaker[]; getAllRetryExecutors(): RetryExecutor[]; getCircuitBreakerStats(): Array<{ name: string; stats: CircuitBreakerStats; }>; resetAllCircuitBreakers(): void; getHealthStatus(): { healthy: boolean; openCircuits: string[]; totalCircuits: number; failedOperations: string[]; }; retryNetworkOperation<T>(operation: () => Promise<T>, options?: Partial<RetryOptions>): Promise<T>; retryFileOperation<T>(operation: () => Promise<T>, options?: Partial<RetryOptions>): Promise<T>; retryDatabaseOperation<T>(operation: () => Promise<T>, options?: Partial<RetryOptions>): Promise<T>; } export declare function createRetryManager(): RetryManager; export declare function getGlobalRetryManager(): RetryManager; export declare function setGlobalRetryManager(manager: RetryManager): void;