Pular para o conteúdo
Português (BR)

CoordinatedShutdown

Este conteúdo não está disponível em sua língua ainda.

Defined in: src/CoordinatedShutdown.ts:81

Lifecycle coordinator that runs registered tasks in well-known phases. Ordinary application code calls addTask(phase, name, task); the runtime guarantees task order across phases and bounded parallelism within a phase. Task failures are logged and do NOT by default abort the rest of the pipeline.

new CoordinatedShutdown(system): CoordinatedShutdown

Defined in: src/CoordinatedShutdown.ts:114

ActorSystem

CoordinatedShutdown

defaultPhaseTimeoutMs: number = DEFAULT_PHASE_TIMEOUT_MS

Defined in: src/CoordinatedShutdown.ts:109

Default per-phase timeout in ms. Can be changed globally or per-phase via setPhaseTimeout, or from actor-ts.coordinated-shutdown. default-phase-timeout. 5 seconds is a reasonable balance between letting slow tasks finish and not blocking shutdown indefinitely.

Assigning it later only affects phases registered after the fact — the 12 canonical phases copy it when they are seeded below, which is why the config read has to happen first.

get isComplete(): boolean

Defined in: src/CoordinatedShutdown.ts:217

True once run() has completed (successful or not).

boolean


get isRunning(): boolean

Defined in: src/CoordinatedShutdown.ts:215

True once run() has been kicked off.

boolean

addPhase(def): void

Defined in: src/CoordinatedShutdown.ts:195

Add a custom phase. dependsOn tells the coordinator where in the order it sits.

PhaseDefinition

void


addTask(phase, name, task): void

Defined in: src/CoordinatedShutdown.ts:164

Register a task to run during the given phase. Task names must be unique within a phase.

string

string

ShutdownTask

void


installProcessHooks(signals?): void

Defined in: src/CoordinatedShutdown.ts:233

Install SIGTERM / SIGINT handlers that call run(ProcessTerminateReason). Calling twice is harmless. Uninstall via removeProcessHooks.

Signals[] = ...

void


removeProcessHooks(): void

Defined in: src/CoordinatedShutdown.ts:246

void


removeTask(phase, name): boolean

Defined in: src/CoordinatedShutdown.ts:185

Unregister a task, returning whether one was there.

A task registered for a resource that has since been released must be able to go with it. Without this, a component that registers on acquire — the HTTP layer’s http-unbind-<host>:<port>, say — could never re-acquire the same resource in one process: the second registration collides with a task whose binding no longer exists.

string

string

boolean


run(reason?): Promise<void>

Defined in: src/CoordinatedShutdown.ts:223

Run the pipeline. Safe to call from multiple sites — subsequent calls return the same in-flight promise.

Reason = UnknownReason.instance

Promise<void>


setPhaseTimeout(phase, timeoutMs): void

Defined in: src/CoordinatedShutdown.ts:208

Override the timeout for a phase. Uses defaultPhaseTimeoutMs by default.

string

number

void