@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
123 lines (122 loc) • 3.07 kB
TypeScript
/**
* Graceful degradation under resource constraints
*/
import { EventEmitter } from 'events';
interface DegradationLevel {
name: string;
priority: number;
memoryThreshold: number;
cpuThreshold: number;
actions: DegradationAction[];
}
interface DegradationAction {
type: 'disable_feature' | 'reduce_quality' | 'limit_concurrency' | 'clear_cache' | 'delay_operations';
target: string;
parameters?: Record<string, any>;
reversible: boolean;
}
interface SystemConstraints {
memory: {
current: number;
limit: number;
available: number;
};
cpu: {
current: number;
limit: number;
};
operations: {
running: number;
queued: number;
limit: number;
};
}
export declare class GracefulDegradation extends EventEmitter {
private static instance;
private currentLevel;
private activatedActions;
private monitoring;
private monitorInterval?;
private degradationLevels;
private constructor();
static getInstance(): GracefulDegradation;
/**
* Start monitoring system constraints
*/
startMonitoring(intervalMs?: number): void;
/**
* Stop monitoring
*/
stopMonitoring(): void;
/**
* Manually trigger degradation to a specific level
*/
degradeToLevel(level: number): void;
/**
* Get current degradation status
*/
getStatus(): {
level: number;
levelName: string;
activatedActions: DegradationAction[];
constraints: SystemConstraints;
};
/**
* Check if a feature is currently disabled
*/
isFeatureDisabled(feature: string): boolean;
/**
* Get current concurrency limit for a target
*/
getConcurrencyLimit(target: string): number | null;
/**
* Get current operation delay for a target
*/
getOperationDelay(target: string): number;
/**
* Add custom degradation level
*/
addDegradationLevel(level: DegradationLevel): void;
/**
* Force garbage collection if available
*/
forceGarbageCollection(): boolean;
/**
* Check current system constraints and apply degradation if needed
*/
private checkConstraints;
/**
* Get current system constraints
*/
private getCurrentConstraints;
/**
* Calculate required degradation level based on constraints
*/
private calculateRequiredDegradationLevel;
/**
* Apply degradation actions for a specific level
*/
private applyDegradationLevel;
/**
* Apply degradation actions
*/
private applyActions;
/**
* Reverse degradation actions
*/
private reverseActions;
/**
* Apply a single degradation action
*/
private applyAction;
/**
* Reverse a single degradation action
*/
private reverseAction;
/**
* Restore normal operation (level 0)
*/
private restoreNormalOperation;
}
export declare const gracefulDegradation: GracefulDegradation;
export {};