コンテンツにスキップ
日本語

CircuitBreakerOptionsType

このコンテンツはまだ日本語訳がありません。

CircuitBreakerOptionsType = object

Defined in: src/pattern/CircuitBreakerOptions.ts:65

Plain options-object shape accepted by a CircuitBreaker.

readonly optional backoffFactor?: number

Defined in: src/pattern/CircuitBreakerOptions.ts:103

Multiplier applied to the reopen window per consecutive open, >= 1. Defaults to DEFAULT_CIRCUIT_BREAKER_BACKOFF_FACTOR (1 — no growth, the shipped behaviour).

The window is resetTimeoutMs * backoffFactor^(consecutive opens - 1), clamped to maxResetTimeoutMs. Below 1 it would shrink, so a breaker would probe a dependency more often the longer that dependency stayed broken — the inverse of what a backoff is for, which is why the validator refuses it rather than treating it as an exotic choice.


readonly optional callTimeoutMs?: number

Defined in: src/pattern/CircuitBreakerOptions.ts:71

Per-call timeout; exceeding this counts as a failure.


readonly optional ignoredErrorNames?: readonly string[]

Defined in: src/pattern/CircuitBreakerOptions.ts:130

Error.name values that never count as a failure. Absent and [] mean the same thing, which is what lets the HOCON leaf publish [].

Checked before isFailure, and that order is the point: this list is the operator’s half of the classifier and arrives from a config file, while isFailure is the developer’s and is compiled in. If the predicate could override the list, an operator adding a name would be writing a key that goes inert for exactly the deployments that needed it.

"CircuitBreakerTimeoutError" is listable and means “a call that blew its own callTimeoutMs does not count against the breaker” — coherent, and surprising enough to be worth saying out loud.


readonly optional isFailure?: (err) => boolean

Defined in: src/pattern/CircuitBreakerOptions.ts:80

Optional: classify errors as non-failures to bypass breaker counting.

Belongs to the instance, so it is right for a breaker built in code and wrong for one resolved by a shared id — there the first caller’s predicate is the only one that ever runs. CircuitBreaker.call takes the same predicate per call for that case, and it wins over this one (#874).

Error

boolean


readonly maxFailures: number

Defined in: src/pattern/CircuitBreakerOptions.ts:67

Consecutive failures before the breaker opens. Must be >= 1.


readonly optional maxResetTimeoutMs?: number

Defined in: src/pattern/CircuitBreakerOptions.ts:91

Ceiling the reopen window may grow to under backoffFactor, in ms. Defaults to DEFAULT_CIRCUIT_BREAKER_MAX_RESET_TIMEOUT_MS.

It bounds the whole window rather than only the growth, so a resetTimeoutMs above the ceiling is a contradiction rather than a silently shortened window — the validator refuses that pair and names this field. Clamping quietly would take a reopen window an operator chose and replace it with one nobody wrote down.


readonly optional random?: () => number

Defined in: src/pattern/CircuitBreakerOptions.ts:138

Override Math.random for deterministic tests. No HOCON leaf and it cannot have one — a config file expresses values, not functions. The same seam RetryOptions.random and BrokerCommonOptionsType.reconnect.random carry, and without it the jittered schedule is only assertable through a range, which is a test that passes for a broken multiplier.

number


readonly optional randomFactor?: number

Defined in: src/pattern/CircuitBreakerOptions.ts:115

Jitter fraction in [0, 1] applied to the reopen window: the delay is multiplied by 1 + random(-randomFactor, +randomFactor). Defaults to DEFAULT_CIRCUIT_BREAKER_RANDOM_FACTOR (0 — no jitter).

Same contract as RetryOptions.randomFactor and ExponentialBackoffOptions.randomFactor. What it buys a breaker is the same thing it buys a reconnect loop: N replicas that opened on one upstream event stop probing it in lockstep, so the recovering dependency meets a spread of probes instead of a synchronised wave.


readonly resetTimeoutMs: number

Defined in: src/pattern/CircuitBreakerOptions.ts:69

How long the breaker stays open before letting a probe through. ms.


readonly optional scheduler?: Scheduler

Defined in: src/pattern/CircuitBreakerOptions.ts:148

Where the breaker reads the time and arms its call timeout. Default: the wall clock.

The reset window is the reason this exists. A realistic one is seconds, so a test of “the breaker reopens after the window” either waits those seconds or shortens the window until it is asserting a shape production never takes. Pass system.scheduler and a ManualScheduler crosses it for free (#1424).