Skip to content

CircuitBreakerOptions

Defined in: src/circuit-breaker.ts:53

T

optional breakDuration?: Duration

Defined in: src/circuit-breaker.ts:79

How long the circuit stays open. Default 5 s.


optional breakDurationGenerator?: (args) => MaybePromise<Duration>

Defined in: src/circuit-breaker.ts:80

BreakDurationArgs

MaybePromise<Duration>


optional breaker?: CircuitBreakerPolicy

Defined in: src/circuit-breaker.ts:95

Custom rule for when a closed circuit opens; replaces failureRatio, minimumThroughput and the sampling window (consecutiveFailures, if set, still applies too).


optional consecutiveFailures?: number

Defined in: src/circuit-breaker.ts:66

Break after this many failures in a row (a success resets the count). Simple and good for low traffic. When set without failureRatio, the ratio check is off and only this rule applies.


optional extensions?: CircuitBreakerExtension[]

Defined in: src/circuit-breaker.ts:113

Background behaviour plugged into the breaker, e.g. circuitHealthCheck({ check, interval }) or sharedCircuitState({ store, key }) from this package. Kept out of the core breaker so you only bundle what you use.


optional failureRatio?: number

Defined in: src/circuit-breaker.ts:61

Failure ratio in the window that breaks the circuit. Default 0.1.


optional halfOpenMaxCalls?: number

Defined in: src/circuit-breaker.ts:85

Probe calls let through while half-open. Default 1 (Polly). When all have finished, the circuit closes if their failure ratio is below failureRatio, and opens again otherwise.


optional halfOpenMaxWait?: Duration

Defined in: src/circuit-breaker.ts:106

How long a half-open probe may run before it counts as a failure and the circuit opens again. Default 30 s. Without it a probe that never settles would keep the circuit half-open (rejecting everything) forever.


optional halfOpenSuccessThreshold?: number

Defined in: src/circuit-breaker.ts:90

Fraction of finished probes that must succeed to close, in (0, 1]; e.g. 0.8 with halfOpenMaxCalls: 5 needs 4 successes. Default: close unless the probes’ failure ratio reaches failureRatio.


optional initialState?: CircuitSnapshot

Defined in: src/circuit-breaker.ts:101

Resume from a snapshot taken with stateProvider.snapshot(), e.g. after a serverless cold start or a restart.


optional manualControl?: CircuitBreakerManualControl

Defined in: src/circuit-breaker.ts:96


optional minimumRps?: number

Defined in: src/circuit-breaker.ts:73

Time window only: also require this many calls per second (averaged over samplingDuration) before the ratio counts, so a quiet period’s few failures can’t open the circuit (cockatiel’s SamplingBreaker minimumRps).


optional minimumThroughput?: number

Defined in: src/circuit-breaker.ts:68

Minimum recorded calls in the window before the ratio is considered. Default 100.


optional name?: string

Defined in: src/circuit-breaker.ts:54


optional onClosed?: (args) => MaybePromise<void>

Defined in: src/circuit-breaker.ts:115

OnCircuitClosedArgs<T>

MaybePromise<void>


optional onHalfOpened?: (args) => MaybePromise<void>

Defined in: src/circuit-breaker.ts:116

ResilienceContext

MaybePromise<void>


optional onOpened?: (args) => MaybePromise<void>

Defined in: src/circuit-breaker.ts:114

OnCircuitOpenedArgs<T>

MaybePromise<void>


optional onRejected?: (args) => MaybePromise<void>

Defined in: src/circuit-breaker.ts:108

Called (and OnCircuitRejected reported) every time the circuit refuses a call: the “short-circuited” count.

OnCircuitRejectedArgs

MaybePromise<void>


optional samplingCount?: number

Defined in: src/circuit-breaker.ts:77

Count-based window: the last samplingCount calls. Better for low or bursty traffic.


optional samplingDuration?: Duration

Defined in: src/circuit-breaker.ts:75

Time-based window: calls of the last samplingDuration. Default 30 s. Ignored when samplingCount is set.


optional shouldHandle?: ShouldHandle<OutcomeArgs<T>>

Defined in: src/circuit-breaker.ts:59

Which outcomes are failures. Default: transient errors (not 4xx except 408/429, not caller aborts). Errors that aren’t failures are ignored, not counted as successes. Rejections from other strategies are never counted.


optional stateProvider?: CircuitBreakerStateProvider

Defined in: src/circuit-breaker.ts:97


optional warmUpDuration?: Duration

Defined in: src/circuit-breaker.ts:99

Don’t open during this period after creation (the window still fills), so a cold start’s first errors can’t trip it.