CircuitBreakerOptions
Defined in: src/circuit-breaker.ts:53
Type Parameters
Section titled “Type Parameters”T
Properties
Section titled “Properties”breakDuration?
Section titled “breakDuration?”
optionalbreakDuration?:Duration
Defined in: src/circuit-breaker.ts:79
How long the circuit stays open. Default 5 s.
breakDurationGenerator?
Section titled “breakDurationGenerator?”
optionalbreakDurationGenerator?: (args) =>MaybePromise<Duration>
Defined in: src/circuit-breaker.ts:80
Parameters
Section titled “Parameters”Returns
Section titled “Returns”breaker?
Section titled “breaker?”
optionalbreaker?: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).
consecutiveFailures?
Section titled “consecutiveFailures?”
optionalconsecutiveFailures?: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.
extensions?
Section titled “extensions?”
optionalextensions?: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.
failureRatio?
Section titled “failureRatio?”
optionalfailureRatio?:number
Defined in: src/circuit-breaker.ts:61
Failure ratio in the window that breaks the circuit. Default 0.1.
halfOpenMaxCalls?
Section titled “halfOpenMaxCalls?”
optionalhalfOpenMaxCalls?: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.
halfOpenMaxWait?
Section titled “halfOpenMaxWait?”
optionalhalfOpenMaxWait?: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.
halfOpenSuccessThreshold?
Section titled “halfOpenSuccessThreshold?”
optionalhalfOpenSuccessThreshold?: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.
initialState?
Section titled “initialState?”
optionalinitialState?: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.
manualControl?
Section titled “manualControl?”
optionalmanualControl?:CircuitBreakerManualControl
Defined in: src/circuit-breaker.ts:96
minimumRps?
Section titled “minimumRps?”
optionalminimumRps?: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).
minimumThroughput?
Section titled “minimumThroughput?”
optionalminimumThroughput?:number
Defined in: src/circuit-breaker.ts:68
Minimum recorded calls in the window before the ratio is considered. Default 100.
optionalname?:string
Defined in: src/circuit-breaker.ts:54
onClosed?
Section titled “onClosed?”
optionalonClosed?: (args) =>MaybePromise<void>
Defined in: src/circuit-breaker.ts:115
Parameters
Section titled “Parameters”Returns
Section titled “Returns”MaybePromise<void>
onHalfOpened?
Section titled “onHalfOpened?”
optionalonHalfOpened?: (args) =>MaybePromise<void>
Defined in: src/circuit-breaker.ts:116
Parameters
Section titled “Parameters”context
Section titled “context”Returns
Section titled “Returns”MaybePromise<void>
onOpened?
Section titled “onOpened?”
optionalonOpened?: (args) =>MaybePromise<void>
Defined in: src/circuit-breaker.ts:114
Parameters
Section titled “Parameters”Returns
Section titled “Returns”MaybePromise<void>
onRejected?
Section titled “onRejected?”
optionalonRejected?: (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.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”MaybePromise<void>
samplingCount?
Section titled “samplingCount?”
optionalsamplingCount?:number
Defined in: src/circuit-breaker.ts:77
Count-based window: the last samplingCount calls. Better for low or bursty traffic.
samplingDuration?
Section titled “samplingDuration?”
optionalsamplingDuration?:Duration
Defined in: src/circuit-breaker.ts:75
Time-based window: calls of the last samplingDuration. Default 30 s. Ignored when samplingCount is set.
shouldHandle?
Section titled “shouldHandle?”
optionalshouldHandle?: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.
stateProvider?
Section titled “stateProvider?”
optionalstateProvider?:CircuitBreakerStateProvider
Defined in: src/circuit-breaker.ts:97
warmUpDuration?
Section titled “warmUpDuration?”
optionalwarmUpDuration?: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.