Skip to content

WorkerHotReloadHooks

Lets app code act on `WorkerManager.hotReload`, in every worker mode. Each hook may be async; one that throws is logged without affecting the reload.

Signature

export interface WorkerHotReloadHooks

Properties

0

No properties.

Methods

4

Methods

onStandby?(): Awaitable<unknown>;

This worker started as a hot reload replacement. It only builds its cache, next to the worker it replaces, until it is activated; app work that must not run twice should wait for `onActivate`. It is awaited during `start()`, so its time counts toward the reload's `readyTimeout`.

onActivate?(info: {    resumed: boolean;}): Awaitable<unknown>;

This worker now handles gateway events. `resumed` is true when a stopped worker takes events back because its replacement failed after the switch, so the app can undo what it did in `onStop`.

onStop?(): Awaitable<unknown>;

This worker was told to stop handling gateway events; its replacement takes over next.

onDrain?(info: {    timeout: number;}): Awaitable<unknown>;

This worker is being retired. Awaited for up to `timeout` ms, alongside in-flight work, before plugin teardown and before its shards end, while REST still works: the place to save state such as music players or recordings. The hook is skipped if the deadline expires while it is waiting behind an earlier hook. Its shards are still connected too, except with `resumeSession`, where the session already moved to the replacement.