deepsource-mcp-server
Version:
Model Context Protocol server for DeepSource
145 lines (144 loc) • 3.72 kB
TypeScript
/**
* @fileoverview Retry budget management to prevent resource exhaustion
* This module implements retry budgets to limit the number of retries within a time window.
*/
/**
* Retry budget configuration
* @interface
* @public
*/
export interface RetryBudgetConfig {
/** Maximum number of retries allowed per time window */
maxRetries: number;
/** Time window in milliseconds */
timeWindow: number;
/** Name for logging purposes */
name?: string;
}
/**
* Retry budget statistics
* @interface
* @public
*/
export interface RetryBudgetStats {
/** Current number of retries consumed */
consumed: number;
/** Maximum retries allowed */
maximum: number;
/** Remaining retries available */
remaining: number;
/** Time until budget resets (ms) */
resetInMs: number;
/** Whether budget is exhausted */
isExhausted: boolean;
/** Percentage of budget consumed */
consumedPercentage: number;
}
/**
* Retry budget implementation
* @class
* @public
*/
export declare class RetryBudget {
private readonly config;
private readonly name;
private retryTimestamps;
/**
* Creates a new retry budget
* @param config Configuration for the retry budget
*/
constructor(config?: Partial<RetryBudgetConfig>);
/**
* Check if a retry can be consumed from the budget
* @returns True if a retry is available
* @public
*/
canRetry(): boolean;
/**
* Consume a retry from the budget
* @returns True if the retry was successfully consumed
* @public
*/
consumeRetry(): boolean;
/**
* Get current budget statistics
* @returns The current budget statistics
* @public
*/
getStats(): RetryBudgetStats;
/**
* Reset the budget (clear all consumed retries)
* @public
*/
reset(): void;
/**
* Clean up expired retry timestamps
* @private
*/
private cleanup;
}
/**
* Retry budget manager for managing multiple budgets
* @class
* @public
*/
export declare class RetryBudgetManager {
private static instance;
private budgets;
private globalBudget;
/**
* Private constructor for singleton pattern
* @private
*/
private constructor();
/**
* Get the singleton instance
* @returns The retry budget manager instance
* @public
*/
static getInstance(): RetryBudgetManager;
/**
* Get or create a budget for an endpoint
* @param endpoint The endpoint name
* @param config Optional configuration overrides
* @returns The retry budget instance
* @public
*/
getBudget(endpoint: string, config?: Partial<RetryBudgetConfig>): RetryBudget;
/**
* Get the global retry budget
* @returns The global retry budget instance
* @public
*/
getGlobalBudget(): RetryBudget;
/**
* Check if both endpoint and global budgets allow a retry
* @param endpoint The endpoint to check
* @returns True if both budgets allow a retry
* @public
*/
canRetry(endpoint: string): boolean;
/**
* Consume a retry from both endpoint and global budgets
* @param endpoint The endpoint to consume from
* @returns True if the retry was successfully consumed from both budgets
* @public
*/
consumeRetry(endpoint: string): boolean;
/**
* Get statistics for all budgets
* @returns Map of budget name to statistics
* @public
*/
getAllStats(): Map<string, RetryBudgetStats>;
/**
* Reset all budgets
* @public
*/
resetAll(): void;
/**
* Clear all budgets (for testing)
* @public
*/
clear(): void;
}