@encore.dev/sdk 2.0.0-beta.5 → 2.0.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- package/app_meta.ts +3 -2
- package/dist/app_meta.d.ts +3 -2
- package/dist/app_meta.js.map +1 -1
- package/dist/internal/runtime/mod.js +3 -2
- package/dist/internal/runtime/mod.js.map +1 -1
- package/dist/internal/runtime/napi/napi.cjs +1 -1
- package/dist/internal/runtime/napi/napi.d.cts +33 -3
- package/dist/internal/runtime/shutdown.d.ts +84 -11
- package/dist/internal/runtime/shutdown.js +279 -44
- package/dist/internal/runtime/shutdown.js.map +1 -1
- package/dist/shutdown/mod.d.ts +42 -6
- package/dist/shutdown/mod.js +41 -6
- package/dist/shutdown/mod.js.map +1 -1
- package/dist/storage/postgres/database.d.ts +10 -0
- package/dist/storage/postgres/database.js +10 -0
- package/dist/storage/postgres/database.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/internal/runtime/mod.ts +3 -2
- package/internal/runtime/napi/napi.cjs +1 -1
- package/internal/runtime/napi/napi.d.cts +33 -3
- package/internal/runtime/shutdown.test.ts +227 -18
- package/internal/runtime/shutdown.ts +322 -46
- package/package.json +1 -1
- package/shutdown/mod.ts +60 -6
- package/storage/postgres/database.ts +10 -0
package/README.md
CHANGED
|
@@ -40,6 +40,20 @@ await tx.commit();
|
|
|
40
40
|
Transactions roll back on async disposal unless explicitly completed; a clean
|
|
41
41
|
scope exit does not commit. Connections return to the pool on async disposal.
|
|
42
42
|
An acquired connection cannot be used or closed while its transaction is active.
|
|
43
|
+
A connection's session settings and role (`SET`, `set_config`, `SET ROLE`) are
|
|
44
|
+
reset before the pool lends it again. Only the statements a query sends are
|
|
45
|
+
seen: a setting a function or procedure changes for the session, such as
|
|
46
|
+
`SELECT set_tenant($1)` calling `set_config(..., false)`, is not, and stays for
|
|
47
|
+
the connection's next borrower. Scope a setting to a transaction with
|
|
48
|
+
`set_config(name, value, true)`:
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
await using tx = await db.write().begin();
|
|
52
|
+
await tx.exec`SELECT set_config('app.tenant_id', ${tenantId}, true)`;
|
|
53
|
+
// Row-level security policies reading app.tenant_id apply here.
|
|
54
|
+
await tx.commit();
|
|
55
|
+
```
|
|
56
|
+
|
|
43
57
|
Streaming queries exclusively borrow their connection or transaction until
|
|
44
58
|
exhausted or closed. `for await` closes a stream when the loop exits early;
|
|
45
59
|
when manually advancing an iterator, call `return()` before reusing its owner.
|
package/app_meta.ts
CHANGED
|
@@ -22,8 +22,9 @@ export interface AppMeta {
|
|
|
22
22
|
* The API gateways that serve this application, keyed by gateway name.
|
|
23
23
|
*
|
|
24
24
|
* An application can declare several gateways, so there is no single base URL for
|
|
25
|
-
* the API — look up the gateway you mean by name.
|
|
26
|
-
*
|
|
25
|
+
* the API — look up the gateway you mean by name. Every process lists them,
|
|
26
|
+
* whether it serves one or not; one told of none, as under `encore test`,
|
|
27
|
+
* reports an empty object.
|
|
27
28
|
*/
|
|
28
29
|
gateways: Record<string, GatewayMeta>;
|
|
29
30
|
|
package/dist/app_meta.d.ts
CHANGED
|
@@ -18,8 +18,9 @@ export interface AppMeta {
|
|
|
18
18
|
* The API gateways that serve this application, keyed by gateway name.
|
|
19
19
|
*
|
|
20
20
|
* An application can declare several gateways, so there is no single base URL for
|
|
21
|
-
* the API — look up the gateway you mean by name.
|
|
22
|
-
*
|
|
21
|
+
* the API — look up the gateway you mean by name. Every process lists them,
|
|
22
|
+
* whether it serves one or not; one told of none, as under `encore test`,
|
|
23
|
+
* reports an empty object.
|
|
23
24
|
*/
|
|
24
25
|
gateways: Record<string, GatewayMeta>;
|
|
25
26
|
/** Information about the environment the app is running in. */
|
package/dist/app_meta.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app_meta.js","sourceRoot":"","sources":["../app_meta.ts"],"names":[],"mappings":"AAAA,OAAO,KA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C;QACrB,KAAK,OAAO,CAAC,eAAe,CAAC,IAAI;YAC/B,OAAO,MAAM,CAAC;QAChB;YACE,OAAO,aAAa,CAAC;IACzB,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CAAC,MAA6B;IAClD,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,OAAO,CAAC,aAAa,CAAC,GAAG;YAC5B,OAAO,KAAK,CAAC;QACf,KAAK,OAAO,CAAC,aAAa,CAAC,GAAG;YAC5B,OAAO,KAAK,CAAC;QACf,KAAK,OAAO,CAAC,aAAa,CAAC,KAAK;YAC9B,OAAO,OAAO,CAAC;QACjB,KAAK,OAAO,CAAC,aAAa,CAAC,MAAM;YAC/B,OAAO,QAAQ,CAAC;QAClB,KAAK,OAAO,CAAC,aAAa,CAAC,KAAK;YAC9B,OAAO,OAAO,CAAC;QACjB;YACE,OAAO,OAAO,CAAC;IACnB,CAAC;AACH,CAAC;AAED,6CAA6C;AAC7C,IAAI,MAAM,GAAmB,IAAI,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Decimal } from '../../types/mod.js';
|
|
2
2
|
import { printRuntimeLine } from '../../log/runtime.js';
|
|
3
|
-
import { watchShutdownSignals } from './shutdown.js';
|
|
3
|
+
import { setShutdownRuntime, watchShutdownSignals } from './shutdown.js';
|
|
4
4
|
import { Runtime, setRuntimeLogHandler } from './napi/napi.cjs';
|
|
5
5
|
export * from './napi/napi.cjs';
|
|
6
6
|
const testMode = process.env.NODE_ENV === 'test';
|
|
@@ -11,8 +11,9 @@ export const RT = new Runtime({
|
|
|
11
11
|
decimal: (val) => new Decimal(val),
|
|
12
12
|
},
|
|
13
13
|
});
|
|
14
|
+
setShutdownRuntime(RT);
|
|
14
15
|
if (!testMode)
|
|
15
|
-
watchShutdownSignals(
|
|
16
|
+
watchShutdownSignals();
|
|
16
17
|
export { runUntilShutdown } from './shutdown.js';
|
|
17
18
|
let cached = null;
|
|
18
19
|
export function runtimeConfig() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../../internal/runtime/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAC,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAC,oBAAoB,EAAC,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../../internal/runtime/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAC,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAC,kBAAkB,EAAE,oBAAoB,EAAC,MAAM,YAAY,CAAC;AACpE,OAAO,EAAC,OAAO,EAAE,oBAAoB,EAAC,MAAM,iBAAiB,CAAC;AAE9D,cAAc,iBAAiB,CAAC;AAEhC,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM,CAAC;AAEjD,oBAAoB,CAAC,gBAAgB,CAAC,CAAC;AAEvC,MAAM,CAAC,MAAM,EAAE,GAAG,IAAI,OAAO,CAAC;IAC5B,QAAQ;IACR,gBAAgB,EAAE;QAChB,OAAO,EAAE,CAAC,GAA6B,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC;KAC7D;CACF,CAAC,CAAC;AAEH,kBAAkB,CAAC,EAAE,CAAC,CAAC;AACvB,IAAI,CAAC,QAAQ;IAAE,oBAAoB,EAAE,CAAC;AAEtC,OAAO,EAAC,gBAAgB,EAAC,MAAM,YAAY,CAAC;AAU5C,IAAI,MAAM,GAAyB,IAAI,CAAC;AACxC,MAAM,UAAU,aAAa;IAC3B,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,MAAM,GAAG,GAAG,EAAE,CAAC,aAAa,EAAE,CAAC;QAC/B,MAAM,GAAG;YACP,cAAc,EAAE,GAAG,CAAC,cAAc;YAClC,QAAQ,EAAE,GAAG,CAAC,QAAQ,IAAI,EAAE;SAC7B,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// The version of the runtime this JS bundle was generated for.
|
|
2
|
-
const version = "v2.0.0-beta.
|
|
2
|
+
const version = "v2.0.0-beta.7";
|
|
3
3
|
|
|
4
4
|
// Load the native module. ENCORE_RUNTIME_LIB overrides the location; by
|
|
5
5
|
// default the library is found by walking up from this file (which the
|
|
@@ -410,12 +410,42 @@ export class Runtime {
|
|
|
410
410
|
beginShutdown(cooperative: boolean): void
|
|
411
411
|
/** Tells the runtime the application has drained its work. */
|
|
412
412
|
markApplicationDrained(): void
|
|
413
|
+
/**
|
|
414
|
+
* Calls `handler` on the event loop as the shutdown begun with
|
|
415
|
+
* [`Runtime::begin_shutdown`] reaches each phase: `"started"`,
|
|
416
|
+
* `"cleanup"`, then `"completed"` with its result, `"success"`,
|
|
417
|
+
* `"timeout"` or `"failed"`. Unlike [`Runtime::shutdown_completed`],
|
|
418
|
+
* watching holds no handle open on the event loop.
|
|
419
|
+
*/
|
|
420
|
+
watchShutdown(handler: (phase: string, result?: string) => void): void
|
|
421
|
+
/**
|
|
422
|
+
* The shutdown's phase: `"not-started"`, `"started"`, `"cleanup"` or
|
|
423
|
+
* `"completed"`.
|
|
424
|
+
*/
|
|
425
|
+
shutdownPhase(): string
|
|
426
|
+
/**
|
|
427
|
+
* How long the shutdown may take before cleanup begins regardless, in
|
|
428
|
+
* milliseconds from its beginning.
|
|
429
|
+
*/
|
|
430
|
+
shutdownTimeoutMs(): number
|
|
431
|
+
/**
|
|
432
|
+
* Begins cleanup without waiting for the app to drain. Fails if the
|
|
433
|
+
* shutdown has not begun.
|
|
434
|
+
*/
|
|
435
|
+
forceShutdownCleanup(): void
|
|
436
|
+
/**
|
|
437
|
+
* Finishes the shutdown of an app that is exiting on its own, blocking
|
|
438
|
+
* until cleanup completes: from `process.on('exit')`, after which no
|
|
439
|
+
* JavaScript runs. Returns the exit code, as
|
|
440
|
+
* [`Runtime::shutdown_completed`] does.
|
|
441
|
+
*/
|
|
442
|
+
finishShutdownSync(): number
|
|
413
443
|
/**
|
|
414
444
|
* Waits for cleanup to complete after [`Runtime::begin_shutdown`],
|
|
415
|
-
* returning
|
|
416
|
-
* deadline,
|
|
445
|
+
* returning its result: `"success"` when it finished within the
|
|
446
|
+
* deadline, `"timeout"` when it did not, or `"failed"`.
|
|
417
447
|
*/
|
|
418
|
-
shutdownCompleted(): Promise<
|
|
448
|
+
shutdownCompleted(): Promise<string>
|
|
419
449
|
sqlDatabase(encoreName: string): SqlDatabase
|
|
420
450
|
pubsubTopic(encoreName: string): PubSubTopic
|
|
421
451
|
bucket(encoreName: string): Bucket
|
|
@@ -1,13 +1,86 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import type { Runtime } from './napi/napi.cjs';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
|
|
3
|
+
/** A phase of Encore's shutdown.
|
|
4
|
+
*
|
|
5
|
+
* - `not-started`: shutdown has not begun.
|
|
6
|
+
* - `started`: Pub/Sub intake has stopped; Encore waits for the message
|
|
7
|
+
* handlers in flight, and for the app's holds.
|
|
8
|
+
* - `cleanup`: Encore is closing its resources and flushing telemetry.
|
|
9
|
+
* - `completed`: cleanup has finished, whatever its result. */
|
|
10
|
+
export type ShutdownPhase = 'not-started' | 'started' | 'cleanup' | 'completed';
|
|
11
|
+
/** How a completed shutdown went: `success` if cleanup finished within the
|
|
12
|
+
* shutdown deadline, else `timeout`. A failed cleanup is a
|
|
13
|
+
* {@link ShutdownError}. */
|
|
14
|
+
export type ShutdownResult = 'success' | 'timeout';
|
|
15
|
+
/** Encore's cleanup failed, or the shutdown was used before it began. */
|
|
16
|
+
export declare class ShutdownError extends Error {
|
|
17
|
+
name: string;
|
|
18
|
+
}
|
|
19
|
+
/** Work the shutdown waits for before Encore cleans up: until it is
|
|
20
|
+
* released, or the shutdown deadline passes. Releasing it twice is harmless.
|
|
21
|
+
* As a `Disposable`, `using` releases it at the end of its scope. */
|
|
22
|
+
export interface ShutdownHold extends Disposable {
|
|
23
|
+
release(): void;
|
|
24
|
+
}
|
|
25
|
+
/** What a shutdown callback is told. */
|
|
26
|
+
export interface ShutdownContext {
|
|
27
|
+
/** Aborts when cleanup begins, the callback done or not: the shutdown
|
|
28
|
+
* deadline passed, or cleanup was forced. */
|
|
29
|
+
signal: AbortSignal;
|
|
30
|
+
/** When the shutdown deadline passes, in milliseconds since the epoch, as
|
|
31
|
+
* `Date.now()` counts them. */
|
|
32
|
+
deadline: number;
|
|
33
|
+
}
|
|
34
|
+
/** Called when shutdown begins. Cleanup waits for what it returns to settle. */
|
|
35
|
+
export type ShutdownCallback = (ctx: ShutdownContext) => void | Promise<void>;
|
|
36
|
+
/** Aborts when shutdown begins: Encore takes no new Pub/Sub messages, and the
|
|
37
|
+
* app should stop taking work too. */
|
|
38
|
+
export declare const signal: AbortSignal;
|
|
39
|
+
/** Sets the runtime the shutdown runs on. */
|
|
40
|
+
export declare function setShutdownRuntime(rt: Runtime): void;
|
|
41
|
+
/** Holds the shutdown back: Encore cleans up once every hold is released, or
|
|
42
|
+
* the shutdown deadline passes. A hold taken once the app has drained, or
|
|
43
|
+
* cleanup has begun, comes released: cleanup does not wait for it. */
|
|
44
|
+
export declare function hold(): ShutdownHold;
|
|
45
|
+
/** Holds the shutdown back until `work` settles. A rejection is logged. */
|
|
46
|
+
export declare function waitUntil(work: PromiseLike<unknown>): void;
|
|
47
|
+
/** Calls `callback` when shutdown begins, or at once if it has, holding
|
|
48
|
+
* cleanup back until it settles. Disposing of the returned value
|
|
49
|
+
* unregisters it. */
|
|
50
|
+
export declare function onShutdown(callback: ShutdownCallback): Disposable;
|
|
51
|
+
/** Registers `callback` as {@link onShutdown} does, as Encore's own: it
|
|
52
|
+
* doesn't stop Encore from waiting for an app that handles the signal itself. */
|
|
53
|
+
export declare function onShutdownInternal(callback: ShutdownCallback): Disposable;
|
|
54
|
+
/** Begins the shutdown, once: Encore stops taking Pub/Sub messages,
|
|
55
|
+
* {@link signal} aborts, and the {@link onShutdown} callbacks run. Encore
|
|
56
|
+
* cleans up once every hold is released, or the shutdown deadline passes.
|
|
57
|
+
* SIGTERM and SIGINT begin it, outside tests. */
|
|
58
|
+
export declare function begin(): void;
|
|
59
|
+
/** The shutdown's phase now. */
|
|
60
|
+
export declare function phase(): ShutdownPhase;
|
|
61
|
+
/** Resolves once the shutdown has begun and Pub/Sub intake has stopped.
|
|
62
|
+
* Waiting does not keep the process alive. */
|
|
63
|
+
export declare function started(): Promise<void>;
|
|
64
|
+
/** Resolves once cleanup begins: the app drained, the shutdown deadline
|
|
65
|
+
* passed, or cleanup was forced. Waiting does not keep the process alive. */
|
|
66
|
+
export declare function cleanup(): Promise<void>;
|
|
67
|
+
/** Resolves with the shutdown's result once cleanup has completed, after the
|
|
68
|
+
* deadline too; rejects with a {@link ShutdownError} if cleanup failed.
|
|
69
|
+
* Waiting keeps the process alive once the shutdown has begun. */
|
|
70
|
+
export declare function completed(): Promise<ShutdownResult>;
|
|
71
|
+
/** Begins cleanup without waiting for the app's holds or the Pub/Sub
|
|
72
|
+
* handlers in flight. Work still running may find its resources closed. */
|
|
73
|
+
export declare function forceCleanup(): void;
|
|
74
|
+
/** Begins the shutdown on SIGTERM or SIGINT, and exits once it completes:
|
|
75
|
+
* with `process.exitCode` (0 unless the app set it) if cleanup finished
|
|
76
|
+
* within the shutdown deadline, else 1. A second SIGINT, a second Ctrl-C,
|
|
77
|
+
* forces cleanup.
|
|
78
|
+
*
|
|
79
|
+
* An app that listens for the signal itself and holds nothing is waited for
|
|
80
|
+
* until it raises the signal again, exits, or has closed everything it had
|
|
81
|
+
* open. */
|
|
82
|
+
export declare function watchShutdownSignals(): void;
|
|
9
83
|
/** Runs `rt` until its shutdown completes, returning the exit code. The
|
|
10
|
-
* runtime handles SIGTERM and SIGINT; on them the
|
|
11
|
-
* waits for
|
|
12
|
-
export declare function runUntilShutdown(
|
|
13
|
-
export {};
|
|
84
|
+
* runtime handles SIGTERM and SIGINT; on them the shutdown begins here too,
|
|
85
|
+
* and cleanup waits for the app's holds. */
|
|
86
|
+
export declare function runUntilShutdown(r: Runtime): Promise<number>;
|
|
@@ -1,56 +1,291 @@
|
|
|
1
|
+
/** Encore's cleanup failed, or the shutdown was used before it began. */
|
|
2
|
+
export class ShutdownError extends Error {
|
|
3
|
+
name = 'ShutdownError';
|
|
4
|
+
}
|
|
1
5
|
const SIGNALS = ['SIGTERM', 'SIGINT'];
|
|
2
|
-
|
|
6
|
+
/** How long after the first signal the same one again is a new one, not the
|
|
7
|
+
* first delivered twice: a process group's runner may forward the signal its
|
|
8
|
+
* members already received. */
|
|
9
|
+
const REPEAT_MS = 1000;
|
|
3
10
|
let runtime;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
/** Whether the runtime runs the process ({@link runUntilShutdown}): it
|
|
12
|
+
* handles the signals natively, and its caller exits. */
|
|
13
|
+
let hosted = false;
|
|
14
|
+
const callbacks = new Set();
|
|
15
|
+
/** The callbacks Encore registered itself, as its API framework's server
|
|
16
|
+
* does: they don't say the app tells Encore of its shutdown. */
|
|
17
|
+
const ownCallbacks = new WeakSet();
|
|
18
|
+
let holds = 0;
|
|
19
|
+
let begun = false;
|
|
20
|
+
let markBegun;
|
|
21
|
+
const begunAt = new Promise(resolve => (markBegun = resolve));
|
|
22
|
+
let deadline = 0;
|
|
23
|
+
/** Whether Encore was told the app has drained: holds count no longer. */
|
|
24
|
+
let drained = false;
|
|
25
|
+
let cleaningUp = false;
|
|
26
|
+
const startAbort = new AbortController();
|
|
27
|
+
const cleanupAbort = new AbortController();
|
|
28
|
+
let markStarted;
|
|
29
|
+
const startedAt = new Promise(resolve => (markStarted = resolve));
|
|
30
|
+
let markCleanup;
|
|
31
|
+
const cleanupAt = new Promise(resolve => (markCleanup = resolve));
|
|
32
|
+
let completion;
|
|
33
|
+
/** The signal that began the shutdown: Encore then exits once it completes. */
|
|
34
|
+
let signalled;
|
|
35
|
+
let signalledAt = 0;
|
|
36
|
+
/** Held for an app that handles the signal itself without telling Encore of
|
|
37
|
+
* its shutdown, until it is done. */
|
|
38
|
+
let appHold;
|
|
39
|
+
/** The signal the app raised again, to die of once Encore has cleaned up. */
|
|
40
|
+
let reraised;
|
|
41
|
+
/** Whether Encore waits for cleanup to complete, to exit. */
|
|
42
|
+
let exiting = false;
|
|
43
|
+
/** Whether the process is on its way out, cleanup completed. */
|
|
44
|
+
let finished = false;
|
|
45
|
+
/** Aborts when shutdown begins: Encore takes no new Pub/Sub messages, and the
|
|
46
|
+
* app should stop taking work too. */
|
|
47
|
+
export const signal = startAbort.signal;
|
|
48
|
+
/** Sets the runtime the shutdown runs on. */
|
|
49
|
+
export function setShutdownRuntime(rt) {
|
|
13
50
|
runtime = rt;
|
|
14
|
-
|
|
15
|
-
|
|
51
|
+
}
|
|
52
|
+
function rt() {
|
|
53
|
+
if (!runtime)
|
|
54
|
+
throw new ShutdownError('the Encore runtime is not loaded');
|
|
55
|
+
return runtime;
|
|
56
|
+
}
|
|
57
|
+
/** Holds the shutdown back: Encore cleans up once every hold is released, or
|
|
58
|
+
* the shutdown deadline passes. A hold taken once the app has drained, or
|
|
59
|
+
* cleanup has begun, comes released: cleanup does not wait for it. */
|
|
60
|
+
export function hold() {
|
|
61
|
+
if (drained || cleaningUp) {
|
|
62
|
+
console.warn('encore: a shutdown hold was taken after the app drained; cleanup does not wait for it');
|
|
63
|
+
const release = () => { };
|
|
64
|
+
return { release, [Symbol.dispose]: release };
|
|
65
|
+
}
|
|
66
|
+
holds++;
|
|
67
|
+
let held = true;
|
|
68
|
+
const release = () => {
|
|
69
|
+
if (!held)
|
|
70
|
+
return;
|
|
71
|
+
held = false;
|
|
72
|
+
holds--;
|
|
73
|
+
settle();
|
|
74
|
+
};
|
|
75
|
+
return { release, [Symbol.dispose]: release };
|
|
76
|
+
}
|
|
77
|
+
/** Holds the shutdown back until `work` settles. A rejection is logged. */
|
|
78
|
+
export function waitUntil(work) {
|
|
79
|
+
const held = hold();
|
|
80
|
+
Promise.resolve(work)
|
|
81
|
+
.then(undefined, err => console.error('encore: shutdown work failed:', err))
|
|
82
|
+
.finally(() => held.release());
|
|
83
|
+
}
|
|
84
|
+
/** Calls `callback` when shutdown begins, or at once if it has, holding
|
|
85
|
+
* cleanup back until it settles. Disposing of the returned value
|
|
86
|
+
* unregisters it. */
|
|
87
|
+
export function onShutdown(callback) {
|
|
88
|
+
callbacks.add(callback);
|
|
89
|
+
if (begun)
|
|
90
|
+
run(callback);
|
|
91
|
+
return { [Symbol.dispose]: () => void callbacks.delete(callback) };
|
|
92
|
+
}
|
|
93
|
+
/** Registers `callback` as {@link onShutdown} does, as Encore's own: it
|
|
94
|
+
* doesn't stop Encore from waiting for an app that handles the signal itself. */
|
|
95
|
+
export function onShutdownInternal(callback) {
|
|
96
|
+
ownCallbacks.add(callback);
|
|
97
|
+
return onShutdown(callback);
|
|
98
|
+
}
|
|
99
|
+
/** Begins the shutdown, once: Encore stops taking Pub/Sub messages,
|
|
100
|
+
* {@link signal} aborts, and the {@link onShutdown} callbacks run. Encore
|
|
101
|
+
* cleans up once every hold is released, or the shutdown deadline passes.
|
|
102
|
+
* SIGTERM and SIGINT begin it, outside tests. */
|
|
103
|
+
export function begin() {
|
|
104
|
+
if (begun)
|
|
105
|
+
return;
|
|
106
|
+
const r = rt();
|
|
107
|
+
begun = true;
|
|
108
|
+
r.beginShutdown(true);
|
|
109
|
+
deadline = Date.now() + r.shutdownTimeoutMs();
|
|
110
|
+
r.watchShutdown(onPhase);
|
|
111
|
+
if (!hosted)
|
|
112
|
+
process.once('exit', finishOnExit);
|
|
113
|
+
markBegun();
|
|
114
|
+
startAbort.abort();
|
|
115
|
+
for (const callback of callbacks)
|
|
116
|
+
run(callback);
|
|
117
|
+
settle();
|
|
118
|
+
}
|
|
119
|
+
/** The shutdown's phase now. */
|
|
120
|
+
export function phase() {
|
|
121
|
+
return (runtime?.shutdownPhase() ?? 'not-started');
|
|
122
|
+
}
|
|
123
|
+
/** Resolves once the shutdown has begun and Pub/Sub intake has stopped.
|
|
124
|
+
* Waiting does not keep the process alive. */
|
|
125
|
+
export function started() {
|
|
126
|
+
return startedAt;
|
|
127
|
+
}
|
|
128
|
+
/** Resolves once cleanup begins: the app drained, the shutdown deadline
|
|
129
|
+
* passed, or cleanup was forced. Waiting does not keep the process alive. */
|
|
130
|
+
export function cleanup() {
|
|
131
|
+
return cleanupAt;
|
|
132
|
+
}
|
|
133
|
+
/** Resolves with the shutdown's result once cleanup has completed, after the
|
|
134
|
+
* deadline too; rejects with a {@link ShutdownError} if cleanup failed.
|
|
135
|
+
* Waiting keeps the process alive once the shutdown has begun. */
|
|
136
|
+
export function completed() {
|
|
137
|
+
return (completion ??= begunAt
|
|
138
|
+
.then(() => rt().shutdownCompleted())
|
|
139
|
+
.then(result => {
|
|
140
|
+
if (result === 'failed') {
|
|
141
|
+
throw new ShutdownError('Encore resource cleanup failed');
|
|
142
|
+
}
|
|
143
|
+
return result;
|
|
144
|
+
}));
|
|
145
|
+
}
|
|
146
|
+
/** Begins cleanup without waiting for the app's holds or the Pub/Sub
|
|
147
|
+
* handlers in flight. Work still running may find its resources closed. */
|
|
148
|
+
export function forceCleanup() {
|
|
149
|
+
if (!begun)
|
|
150
|
+
throw new ShutdownError('shutdown has not begun');
|
|
151
|
+
rt().forceShutdownCleanup();
|
|
152
|
+
}
|
|
153
|
+
/** Begins the shutdown on SIGTERM or SIGINT, and exits once it completes:
|
|
154
|
+
* with `process.exitCode` (0 unless the app set it) if cleanup finished
|
|
155
|
+
* within the shutdown deadline, else 1. A second SIGINT, a second Ctrl-C,
|
|
156
|
+
* forces cleanup.
|
|
157
|
+
*
|
|
158
|
+
* An app that listens for the signal itself and holds nothing is waited for
|
|
159
|
+
* until it raises the signal again, exits, or has closed everything it had
|
|
160
|
+
* open. */
|
|
161
|
+
export function watchShutdownSignals() {
|
|
162
|
+
for (const s of SIGNALS)
|
|
163
|
+
process.on(s, onSignal);
|
|
16
164
|
}
|
|
17
165
|
/** Runs `rt` until its shutdown completes, returning the exit code. The
|
|
18
|
-
* runtime handles SIGTERM and SIGINT; on them the
|
|
19
|
-
* waits for
|
|
20
|
-
export function runUntilShutdown(
|
|
21
|
-
runtime =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
166
|
+
* runtime handles SIGTERM and SIGINT; on them the shutdown begins here too,
|
|
167
|
+
* and cleanup waits for the app's holds. */
|
|
168
|
+
export function runUntilShutdown(r) {
|
|
169
|
+
runtime = r;
|
|
170
|
+
hosted = true;
|
|
171
|
+
return r.runForever(true);
|
|
172
|
+
}
|
|
173
|
+
function onSignal(sig) {
|
|
174
|
+
if (hosted)
|
|
175
|
+
return begin();
|
|
176
|
+
if (signalled || begun)
|
|
177
|
+
return repeated(sig);
|
|
178
|
+
signalled = sig;
|
|
179
|
+
signalledAt = Date.now();
|
|
180
|
+
if (!appTellsShutdown() && process.listenerCount(sig) > 1) {
|
|
181
|
+
// The app's own listeners run after this one, and may take their time.
|
|
182
|
+
appHold = hold();
|
|
183
|
+
console.warn(`encore: the app handles ${sig} itself; Encore cleans up once it is done. ` +
|
|
184
|
+
'Register its shutdown with onShutdown() from @encore.dev/sdk/shutdown to say when.');
|
|
25
185
|
}
|
|
26
|
-
|
|
186
|
+
process.on('beforeExit', onIdle);
|
|
187
|
+
begin();
|
|
27
188
|
}
|
|
28
|
-
|
|
29
|
-
|
|
189
|
+
/** Whether the app holds the shutdown back, or has callbacks of its own. */
|
|
190
|
+
function appTellsShutdown() {
|
|
191
|
+
if (holds > 0)
|
|
192
|
+
return true;
|
|
193
|
+
for (const callback of callbacks) {
|
|
194
|
+
if (!ownCallbacks.has(callback))
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
function repeated(sig) {
|
|
200
|
+
if (!signalled)
|
|
30
201
|
return;
|
|
31
|
-
signalled
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
drain(rt);
|
|
37
|
-
rt.shutdownCompleted().then(code => process.exit(code), () => process.exit(1));
|
|
38
|
-
}
|
|
39
|
-
function drainOnce() {
|
|
40
|
-
if (signalled)
|
|
202
|
+
if (appHold && sig === signalled && process.listenerCount(sig) === 1) {
|
|
203
|
+
// The app raised the signal again, having removed its own listener. Only
|
|
204
|
+
// the signal it handled counts: another may arrive while it still runs.
|
|
205
|
+
reraised = sig;
|
|
206
|
+
appHold.release();
|
|
41
207
|
return;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
208
|
+
}
|
|
209
|
+
if (sig === 'SIGINT' && Date.now() - signalledAt > REPEAT_MS) {
|
|
210
|
+
rt().forceShutdownCleanup();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/** The event loop emptied. An app handling the signal itself is done; other
|
|
214
|
+
* holds are still waited for, until the deadline, as work that holds nothing
|
|
215
|
+
* open on the event loop may yet release them. */
|
|
216
|
+
function onIdle() {
|
|
217
|
+
// A turn later, as a signal the app raised as it closed its last handle is
|
|
218
|
+
// read in that turn: it says how the app meant to end.
|
|
219
|
+
setImmediate(() => {
|
|
220
|
+
appHold?.release();
|
|
221
|
+
if (!finished)
|
|
222
|
+
exitOnCompletion();
|
|
54
223
|
});
|
|
55
224
|
}
|
|
225
|
+
function settle() {
|
|
226
|
+
if (begun && !drained && holds === 0)
|
|
227
|
+
markDrained();
|
|
228
|
+
}
|
|
229
|
+
function markDrained() {
|
|
230
|
+
drained = true;
|
|
231
|
+
rt().markApplicationDrained();
|
|
232
|
+
// Now the app is done, the wait may hold the event loop open.
|
|
233
|
+
if (signalled)
|
|
234
|
+
exitOnCompletion();
|
|
235
|
+
}
|
|
236
|
+
/** Exits once cleanup completes, holding the event loop open till then. */
|
|
237
|
+
function exitOnCompletion() {
|
|
238
|
+
if (exiting)
|
|
239
|
+
return;
|
|
240
|
+
exiting = true;
|
|
241
|
+
completed().then(result => exit(result), () => exit('failed'));
|
|
242
|
+
}
|
|
243
|
+
function onPhase(phase, result) {
|
|
244
|
+
reached(phase);
|
|
245
|
+
// Cleanup also completes once the shutdown deadline passes, the app done
|
|
246
|
+
// or not; the exit code then says it was cut short.
|
|
247
|
+
if (phase === 'completed' && signalled)
|
|
248
|
+
exit(result ?? 'failed');
|
|
249
|
+
}
|
|
250
|
+
/** Settles what waits for `phase`, and for the phases before it. */
|
|
251
|
+
function reached(phase) {
|
|
252
|
+
if (phase === 'cleanup' || phase === 'completed') {
|
|
253
|
+
cleaningUp = true;
|
|
254
|
+
cleanupAbort.abort();
|
|
255
|
+
markCleanup();
|
|
256
|
+
}
|
|
257
|
+
markStarted();
|
|
258
|
+
}
|
|
259
|
+
/** Exits with 1 if cleanup failed or timed out, else as the app meant to:
|
|
260
|
+
* dying of the signal it raised again, or with its own exit code. */
|
|
261
|
+
function exit(result) {
|
|
262
|
+
if (finished)
|
|
263
|
+
return;
|
|
264
|
+
finished = true;
|
|
265
|
+
// Completion may be heard of before the phases leading to it.
|
|
266
|
+
reached('completed');
|
|
267
|
+
if (result !== 'success')
|
|
268
|
+
process.exit(1);
|
|
269
|
+
if (reraised) {
|
|
270
|
+
for (const s of SIGNALS)
|
|
271
|
+
process.off(s, onSignal);
|
|
272
|
+
process.kill(process.pid, reraised);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
process.exit();
|
|
276
|
+
}
|
|
277
|
+
/** An app that exits itself leaves no turn of the event loop to wait in:
|
|
278
|
+
* cleanup finishes here, blocking, and a failure overrides its exit code. */
|
|
279
|
+
function finishOnExit() {
|
|
280
|
+
if (finished)
|
|
281
|
+
return;
|
|
282
|
+
finished = true;
|
|
283
|
+
const code = rt().finishShutdownSync();
|
|
284
|
+
if (code !== 0)
|
|
285
|
+
process.exitCode = code;
|
|
286
|
+
}
|
|
287
|
+
function run(callback) {
|
|
288
|
+
const ctx = { signal: cleanupAbort.signal, deadline };
|
|
289
|
+
waitUntil((async () => callback(ctx))());
|
|
290
|
+
}
|
|
56
291
|
//# sourceMappingURL=shutdown.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shutdown.js","sourceRoot":"","sources":["../../../internal/runtime/shutdown.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shutdown.js","sourceRoot":"","sources":["../../../internal/runtime/shutdown.ts"],"names":[],"mappings":"AAgBA,yEAAyE;AACzE,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC7B,IAAI,GAAG,eAAe,CAAC;CACjC;AAsBD,MAAM,OAAO,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAU,CAAC;AAC/C;;+BAE+B;AAC/B,MAAM,SAAS,GAAG,IAAI,CAAC;AAEvB,IAAI,OAA4B,CAAC;AACjC;yDACyD;AACzD,IAAI,MAAM,GAAG,KAAK,CAAC;AACnB,MAAM,SAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;AAC9C;gEACgE;AAChE,MAAM,YAAY,GAAG,IAAI,OAAO,EAAoB,CAAC;AACrD,IAAI,KAAK,GAAG,CAAC,CAAC;AACd,IAAI,KAAK,GAAG,KAAK,CAAC;AAClB,IAAI,SAAsB,CAAC;AAC3B,MAAM,OAAO,GAAG,IAAI,OAAO,CAAO,OAAO,CAAC,EAAE,CAAC,CAAC,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC;AACpE,IAAI,QAAQ,GAAG,CAAC,CAAC;AACjB,0EAA0E;AAC1E,IAAI,OAAO,GAAG,KAAK,CAAC;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