velocious 1.0.524 → 1.0.526
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 +6 -2
- package/build/background-jobs/main.js +48 -5
- package/build/background-jobs/store.js +28 -7
- package/build/background-jobs/worker.js +126 -7
- package/build/configuration-types.js +9 -0
- package/build/configuration.js +9 -1
- package/build/src/background-jobs/main.d.ts +12 -0
- package/build/src/background-jobs/main.d.ts.map +1 -1
- package/build/src/background-jobs/main.js +48 -6
- package/build/src/background-jobs/store.d.ts +2 -2
- package/build/src/background-jobs/store.d.ts.map +1 -1
- package/build/src/background-jobs/store.js +30 -9
- package/build/src/background-jobs/worker.d.ts +85 -2
- package/build/src/background-jobs/worker.d.ts.map +1 -1
- package/build/src/background-jobs/worker.js +116 -8
- package/build/src/configuration-types.d.ts +21 -0
- package/build/src/configuration-types.d.ts.map +1 -1
- package/build/src/configuration-types.js +10 -1
- package/build/src/configuration.d.ts.map +1 -1
- package/build/src/configuration.js +10 -2
- package/package.json +1 -1
- package/src/background-jobs/main.js +48 -5
- package/src/background-jobs/store.js +28 -7
- package/src/background-jobs/worker.js +126 -7
- package/src/configuration-types.js +9 -0
- package/src/configuration.js +9 -1
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-forked-child timeout bookkeeping.
|
|
3
|
+
* @typedef {object} ForkedJobTimeoutState
|
|
4
|
+
* @property {boolean} timedOut - Whether the timeout fired and the child was terminated.
|
|
5
|
+
* @property {number | null} timeoutMs - The armed timeout in ms, or null when disabled.
|
|
6
|
+
* @property {ReturnType<typeof setTimeout> | null} timer - The pending timeout timer, cleared on exit.
|
|
7
|
+
* @property {ReturnType<typeof setTimeout> | null} sigkillTimer - The pending SIGKILL grace timer, cleared on exit.
|
|
8
|
+
*/
|
|
1
9
|
export default class BackgroundJobsWorker {
|
|
2
10
|
/**
|
|
3
11
|
* Runs constructor.
|
|
@@ -9,8 +17,9 @@ export default class BackgroundJobsWorker {
|
|
|
9
17
|
* @param {number} [args.maxConcurrentInlineJobs] - Override the inline-job concurrency cap from `configuration.getBackgroundJobsConfig()`.
|
|
10
18
|
* @param {number} [args.forkedChildSigkillGraceMs] - Override the grace period between SIGTERM and SIGKILL when reaping lingering process runners on stop.
|
|
11
19
|
* @param {number} [args.heartbeatIntervalMs] - Override the liveness heartbeat interval (default 15000ms).
|
|
20
|
+
* @param {number} [args.jobTimeoutMs] - Override the forked-job wall-clock timeout from `configuration.getBackgroundJobsConfig()`. `0` disables it.
|
|
12
21
|
*/
|
|
13
|
-
constructor({ configuration, host, port, maxConcurrentForkedJobs, maxConcurrentInlineJobs, forkedChildSigkillGraceMs, heartbeatIntervalMs }?: {
|
|
22
|
+
constructor({ configuration, host, port, maxConcurrentForkedJobs, maxConcurrentInlineJobs, forkedChildSigkillGraceMs, heartbeatIntervalMs, jobTimeoutMs }?: {
|
|
14
23
|
configuration?: import("../configuration.js").default | undefined;
|
|
15
24
|
host?: string | undefined;
|
|
16
25
|
port?: number | undefined;
|
|
@@ -18,6 +27,7 @@ export default class BackgroundJobsWorker {
|
|
|
18
27
|
maxConcurrentInlineJobs?: number | undefined;
|
|
19
28
|
forkedChildSigkillGraceMs?: number | undefined;
|
|
20
29
|
heartbeatIntervalMs?: number | undefined;
|
|
30
|
+
jobTimeoutMs?: number | undefined;
|
|
21
31
|
});
|
|
22
32
|
/**
|
|
23
33
|
* Narrows the runtime value to the documented type.
|
|
@@ -56,6 +66,13 @@ export default class BackgroundJobsWorker {
|
|
|
56
66
|
* @type {number}
|
|
57
67
|
*/
|
|
58
68
|
forkedChildSigkillGraceMs: number;
|
|
69
|
+
/**
|
|
70
|
+
* Constructor override for the forked-job wall-clock timeout. When unset the
|
|
71
|
+
* timeout is read from `configuration.getBackgroundJobsConfig().jobTimeoutMs`
|
|
72
|
+
* at fork time (default: disabled).
|
|
73
|
+
* @type {number | undefined}
|
|
74
|
+
*/
|
|
75
|
+
jobTimeoutMsOverride: number | undefined;
|
|
59
76
|
shouldStop: boolean;
|
|
60
77
|
workerId: `${string}-${string}-${string}-${string}-${string}`;
|
|
61
78
|
heartbeatIntervalMs: number;
|
|
@@ -249,6 +266,49 @@ export default class BackgroundJobsWorker {
|
|
|
249
266
|
id: string;
|
|
250
267
|
};
|
|
251
268
|
}): Promise<void>;
|
|
269
|
+
/**
|
|
270
|
+
* Arms a wall-clock backstop for a forked job runner. A forked job still
|
|
271
|
+
* running after `jobTimeoutMs` is terminated (SIGTERM, then SIGKILL after the
|
|
272
|
+
* grace) so a single genuinely-hung runner can't pin a draining worker — and
|
|
273
|
+
* its full-app boot and database connections — indefinitely. Returns a state
|
|
274
|
+
* object the exit/error handlers use to cancel the timer and to report a
|
|
275
|
+
* timeout-specific failure. When no timeout is configured the timer is null
|
|
276
|
+
* and behavior is unchanged.
|
|
277
|
+
* @param {object} args - Options.
|
|
278
|
+
* @param {import("node:child_process").ChildProcess} args.child - Forked child process.
|
|
279
|
+
* @returns {ForkedJobTimeoutState} - Timeout state.
|
|
280
|
+
*/
|
|
281
|
+
_armForkedJobTimeout({ child }: {
|
|
282
|
+
child: import("node:child_process").ChildProcess;
|
|
283
|
+
}): ForkedJobTimeoutState;
|
|
284
|
+
/**
|
|
285
|
+
* Resolves the effective forked-job timeout in ms, or null when disabled. The
|
|
286
|
+
* constructor override wins; otherwise the value comes from the background-jobs
|
|
287
|
+
* configuration. A non-positive value disables the backstop.
|
|
288
|
+
* @returns {number | null} - Timeout in ms, or null when disabled.
|
|
289
|
+
*/
|
|
290
|
+
_resolveForkedJobTimeoutMs(): number | null;
|
|
291
|
+
/**
|
|
292
|
+
* Fired when a forked runner overruns its timeout. Sends SIGTERM for a clean
|
|
293
|
+
* shutdown, then SIGKILL after the grace for a runner that ignores it. The
|
|
294
|
+
* resulting non-clean exit flows through `_handleForkedChildExit`, which frees
|
|
295
|
+
* the slot and reports the job failed.
|
|
296
|
+
* @param {object} args - Options.
|
|
297
|
+
* @param {import("node:child_process").ChildProcess} args.child - Forked child process.
|
|
298
|
+
* @param {ForkedJobTimeoutState} args.state - Timeout state.
|
|
299
|
+
* @returns {void}
|
|
300
|
+
*/
|
|
301
|
+
_onForkedJobTimeout({ child, state }: {
|
|
302
|
+
child: import("node:child_process").ChildProcess;
|
|
303
|
+
state: ForkedJobTimeoutState;
|
|
304
|
+
}): void;
|
|
305
|
+
/**
|
|
306
|
+
* Cancels any pending timeout/SIGKILL timers for a forked runner that has
|
|
307
|
+
* exited (or errored) so they never fire against a gone or reused child.
|
|
308
|
+
* @param {ForkedJobTimeoutState} state - Timeout state.
|
|
309
|
+
* @returns {void}
|
|
310
|
+
*/
|
|
311
|
+
_clearForkedJobTimeout(state: ForkedJobTimeoutState): void;
|
|
252
312
|
/**
|
|
253
313
|
* Runs handle forked child exit.
|
|
254
314
|
* @param {object} args - Options.
|
|
@@ -257,9 +317,10 @@ export default class BackgroundJobsWorker {
|
|
|
257
317
|
* @param {keyof typeof import("node:os").constants.signals | null} args.signal - Exit signal.
|
|
258
318
|
* @param {import("./types.js").BackgroundJobPayload & {id: string}} args.payload - Payload.
|
|
259
319
|
* @param {(value: void) => void} args.resolve - Promise resolver.
|
|
320
|
+
* @param {ForkedJobTimeoutState} [args.timeoutState] - Timeout state, when the runner had a wall-clock backstop.
|
|
260
321
|
* @returns {void}
|
|
261
322
|
*/
|
|
262
|
-
_handleForkedChildExit({ child, code, signal, payload, resolve }: {
|
|
323
|
+
_handleForkedChildExit({ child, code, signal, payload, resolve, timeoutState }: {
|
|
263
324
|
child: import("node:child_process").ChildProcess;
|
|
264
325
|
code: number | null;
|
|
265
326
|
signal: keyof typeof import("node:os").constants.signals | null;
|
|
@@ -267,6 +328,7 @@ export default class BackgroundJobsWorker {
|
|
|
267
328
|
id: string;
|
|
268
329
|
};
|
|
269
330
|
resolve: (value: void) => void;
|
|
331
|
+
timeoutState?: ForkedJobTimeoutState | undefined;
|
|
270
332
|
}): void;
|
|
271
333
|
/**
|
|
272
334
|
* Runs forked child exited cleanly.
|
|
@@ -369,6 +431,27 @@ export default class BackgroundJobsWorker {
|
|
|
369
431
|
workerId?: string | undefined;
|
|
370
432
|
}): void;
|
|
371
433
|
}
|
|
434
|
+
/**
|
|
435
|
+
* Per-forked-child timeout bookkeeping.
|
|
436
|
+
*/
|
|
437
|
+
export type ForkedJobTimeoutState = {
|
|
438
|
+
/**
|
|
439
|
+
* - Whether the timeout fired and the child was terminated.
|
|
440
|
+
*/
|
|
441
|
+
timedOut: boolean;
|
|
442
|
+
/**
|
|
443
|
+
* - The armed timeout in ms, or null when disabled.
|
|
444
|
+
*/
|
|
445
|
+
timeoutMs: number | null;
|
|
446
|
+
/**
|
|
447
|
+
* - The pending timeout timer, cleared on exit.
|
|
448
|
+
*/
|
|
449
|
+
timer: ReturnType<typeof setTimeout> | null;
|
|
450
|
+
/**
|
|
451
|
+
* - The pending SIGKILL grace timer, cleared on exit.
|
|
452
|
+
*/
|
|
453
|
+
sigkillTimer: ReturnType<typeof setTimeout> | null;
|
|
454
|
+
};
|
|
372
455
|
import JsonSocket from "./json-socket.js";
|
|
373
456
|
import BackgroundJobsStatusReporter from "./status-reporter.js";
|
|
374
457
|
//# sourceMappingURL=worker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../../src/background-jobs/worker.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../../src/background-jobs/worker.js"],"names":[],"mappings":"AA8BA;;;;;;;GAOG;AAEH;IACE;;;;;;;;;;;OAWG;IACH,4JATG;QAAqD,aAAa;QAC5C,IAAI;QACJ,IAAI;QACJ,uBAAuB;QACvB,uBAAuB;QACvB,yBAAyB;QACzB,mBAAmB;QACnB,YAAY;KACpC,EAmGA;IAjGC;;gEAE4D;IAC5D,sBADU,OAAO,CAAC,OAAO,qBAAqB,EAAE,OAAO,CAAC,CAC4C;IACpG;;mEAE+D;IAC/D,eADU,OAAO,q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