/** * Copyright (c) 2025 Databricks Contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import IClientContext from '../contracts/IClientContext'; export declare enum CircuitBreakerState { CLOSED = "CLOSED", OPEN = "OPEN", HALF_OPEN = "HALF_OPEN" } export interface CircuitBreakerConfig { failureThreshold: number; timeout: number; successThreshold: number; } export declare const DEFAULT_CIRCUIT_BREAKER_CONFIG: Readonly; export declare const CIRCUIT_BREAKER_OPEN_CODE: "CIRCUIT_BREAKER_OPEN"; /** * Thrown when execute() is called while the breaker is OPEN or a HALF_OPEN * probe is already in flight. Callers identify the condition via * `instanceof CircuitBreakerOpenError` or `err.code === CIRCUIT_BREAKER_OPEN_CODE` * rather than string-matching the message. */ export declare class CircuitBreakerOpenError extends Error { readonly code: "CIRCUIT_BREAKER_OPEN"; constructor(message?: string); } export declare class CircuitBreaker { private context; private state; private failureCount; private successCount; private nextAttempt?; private halfOpenInflight; private readonly config; constructor(context: IClientContext, config?: Partial); execute(operation: () => Promise): Promise; /** * Synchronous admission check. Returning `null` means "reject". Returning * an object means the caller is admitted; `wasHalfOpenProbe` indicates * whether this admission consumed the single HALF_OPEN probe slot so the * caller can decrement it in `finally`. * * Running this as a single synchronous block is what prevents the * concurrent-probe race that existed in the previous implementation. */ private tryAdmit; getState(): CircuitBreakerState; getFailureCount(): number; getSuccessCount(): number; private onSuccess; private onFailure; } export declare class CircuitBreakerRegistry { private context; private breakers; constructor(context: IClientContext); getCircuitBreaker(host: string, config?: Partial): CircuitBreaker; getAllBreakers(): Map; removeCircuitBreaker(host: string): void; clear(): void; }