Ir al contenido
Español

RestartBudget

Esta página aún no está disponible en tu idioma.

Defined in: src/Supervision.ts:75

Sliding-window restart tally for one supervision scope.

Kept apart from SupervisorStrategy on purpose: a strategy is a description — immutable, and shared by design, since defaultStrategy is a module-level singleton handed to every actor that does not override it. A counter living on the strategy would therefore make the whole process share one allowance. The tally belongs to whoever is doing the supervising, so each supervisor owns its own budget over a strategy it merely reads.

maxRetries is read literally: maxRetries restarts are granted, and the attempt that would be number maxRetries + 1 is refused. Only granted restarts are recorded, which is what makes maxRetries: 0 mean “never restart” rather than “restart once”.

The array is bounded by maxRetries for the same reason — once the budget is full nothing more is pushed — so it cannot grow for the lifetime of the process even with withinTimeRangeMs: 0, where no pruning ever happens.

now is injectable so the window can be exercised without sleeping: the only alternative is a real withinTimeRangeMs wait per assertion, which is both slow and the classic source of a timing-flaky suite.

new RestartBudget(strategy, now?): RestartBudget

Defined in: src/Supervision.ts:78

Pick<SupervisorStrategy, "maxRetries" | "withinTimeRangeMs">

Only the two allowance fields are read, and the parameter says so: the worker mesh budgets its slot respawns through this class (#734) and has neither an actor to apply a Directive to nor a supervision scope to name, so requiring a whole SupervisorStrategy would only have it fabricate both. A SupervisorStrategy still satisfies it.

() => number

RestartBudget

get recordedRestarts(): number

Defined in: src/Supervision.ts:110

How many restarts are currently on record — for diagnostics and tests.

number

registerRestart(): boolean

Defined in: src/Supervision.ts:97

Ask for one restart: true when it is granted and recorded, false when the budget is spent and the caller has to do something other than restart.

An unlimited strategy (maxRetries < 0) answers before touching the array, so the common case costs nothing and records nothing.

boolean