@gati-framework/runtime
Version:
Gati runtime execution engine for running handler-based applications
139 lines • 4.17 kB
TypeScript
/**
* @module runtime/lifecycle-manager
* @description Comprehensive lifecycle management for distributed Gati applications
*/
import type { HealthStatus, LifecycleCoordinator } from './types/context.js';
import { LifecyclePriority, RequestPhase } from './types/context.js';
/**
* Distributed lifecycle manager
*/
export declare class LifecycleManager {
private startupHooks;
private shutdownHooks;
private preShutdownHooks;
private healthChecks;
private configReloadHooks;
private memoryPressureHooks;
private circuitBreakerHooks;
private isShuttingDownFlag;
private coordinator?;
constructor(coordinator?: LifecycleCoordinator);
/**
* Register startup hook
*/
onStartup(nameOrFn: string | (() => void | Promise<void>), fnOrPriority?: (() => void | Promise<void>) | LifecyclePriority, maybePriority?: LifecyclePriority): void;
/**
* Register health check
*/
onHealthCheck(name: string, fn: () => Promise<{
status: 'pass' | 'fail' | 'warn';
message?: string;
}>): void;
/**
* Register shutdown hook
*/
onShutdown(nameOrFn: string | (() => void | Promise<void>), fnOrPriority?: (() => void | Promise<void>) | LifecyclePriority, maybePriority?: LifecyclePriority): void;
/**
* Register pre-shutdown hook
*/
onPreShutdown(nameOrFn: string | (() => void | Promise<void>), maybeFn?: () => void | Promise<void>): void;
/**
* Register config reload hook
*/
onConfigReload(name: string, fn: (newConfig: Record<string, unknown>) => void | Promise<void>): void;
/**
* Register memory pressure hook
*/
onMemoryPressure(name: string, fn: (level: 'low' | 'medium' | 'high') => void | Promise<void>): void;
/**
* Register circuit breaker hook
*/
onCircuitBreakerChange(name: string, fn: (service: string, state: 'open' | 'closed' | 'half-open') => void): void;
/**
* Execute startup hooks
*/
executeStartup(): Promise<void>;
/**
* Execute health checks
*/
executeHealthChecks(): Promise<HealthStatus>;
/**
* Execute shutdown hooks
*/
executeShutdown(): Promise<void>;
/**
* Trigger config reload
*/
reloadConfig(newConfig: Record<string, unknown>): Promise<void>;
/**
* Trigger memory pressure handlers
*/
handleMemoryPressure(level: 'low' | 'medium' | 'high'): Promise<void>;
/**
* Trigger circuit breaker change handlers
*/
handleCircuitBreakerChange(service: string, state: 'open' | 'closed' | 'half-open'): void;
/**
* Check if shutting down
*/
isShuttingDown(): boolean;
}
/**
* Request lifecycle manager for individual requests
*/
export declare class RequestLifecycleManager {
private cleanupHooks;
private timeoutHandlers;
private errorHandlers;
private phaseChangeHandlers;
private currentPhase;
private isCleaningUpFlag;
private isTimedOutFlag;
private startTime;
constructor(timeout?: number);
/**
* Register cleanup hook
*/
onCleanup(nameOrFn: string | (() => void | Promise<void>), maybeFn?: () => void | Promise<void>): void;
/**
* Register timeout handler
*/
onTimeout(fn: () => void | Promise<void>): void;
/**
* Register error handler
*/
onError(fn: (error: Error) => void | Promise<void>): void;
/**
* Register phase change handler
*/
onPhaseChange(fn: (phase: RequestPhase, previousPhase: RequestPhase) => void): void;
/**
* Set current request phase
*/
setPhase(phase: RequestPhase): void;
/**
* Execute cleanup hooks
*/
executeCleanup(): Promise<void>;
/**
* Execute timeout handlers
*/
private executeTimeoutHandlers;
/**
* Execute error handlers
*/
executeErrorHandlers(error: Error): Promise<void>;
/**
* Check if cleaning up
*/
isCleaningUp(): boolean;
/**
* Check if timed out
*/
isTimedOut(): boolean;
/**
* Get request duration
*/
getDuration(): number;
}
//# sourceMappingURL=lifecycle-manager.d.ts.map