clyops-jobs 0.6.0 → 0.7.0
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 +1 -1
- package/clyops-jobs.cjs +9 -4
- package/dist/functions.d.ts +1 -0
- package/dist/functions.d.ts.map +1 -1
- package/dist/functions.js +1 -1
- package/package.json +2 -2
- package/src/functions.ts +2 -1
package/README.md
CHANGED
|
@@ -63,7 +63,7 @@ record = transitionJobRecord(record, { status: 'done', completedAt: timestampIso
|
|
|
63
63
|
`runScriptFunction` options: `configRoot` (relative path options resolve against it),
|
|
64
64
|
`context`, `controlled` (options the trigger sets itself, default `['help']`), `defaultPositional`
|
|
65
65
|
(a template for the first argument when the config gives none, e.g. `'${media.path}'`),
|
|
66
|
-
`timeoutMs`, `env`, `cwd`, `signal`, `onStderr`, `onProgress`, `onLog`. Its `command` shows secret options as `***`.
|
|
66
|
+
`timeoutMs`, `killGraceMs`, `env`, `cwd`, `signal`, `onStderr`, `onProgress`, `onLog`. Its `command` shows secret options as `***`.
|
|
67
67
|
|
|
68
68
|
When the tool declares the well-known [roles](https://github.com/wankdanker/clyops/blob/main/spec/SPEC.md#14-roles-on-file-descriptors),
|
|
69
69
|
the run wires them up: each `progress` object goes to `onProgress` (and the last one is the run's
|
package/clyops-jobs.cjs
CHANGED
|
@@ -345,8 +345,9 @@ var import_node_child_process2 = require("node:child_process");
|
|
|
345
345
|
var import_node_stream = require("node:stream");
|
|
346
346
|
var import_node_string_decoder = require("node:string_decoder");
|
|
347
347
|
var ROLE_NAME = /^[A-Za-z][A-Za-z0-9_.-]*$/;
|
|
348
|
-
var
|
|
348
|
+
var KILL_GRACE_MS = 200;
|
|
349
349
|
var STOP_WAIT_MS = 1e3;
|
|
350
|
+
var MAX_DELAY_MS = 2 ** 31 - 1;
|
|
350
351
|
function terminateTree(child, signal) {
|
|
351
352
|
const pid = child.pid;
|
|
352
353
|
if (!pid || pid <= 0) return Promise.resolve();
|
|
@@ -381,6 +382,8 @@ function start(file, argv, opts = {}) {
|
|
|
381
382
|
windowsHide: true
|
|
382
383
|
});
|
|
383
384
|
const limit = opts.maxOutput || Infinity;
|
|
385
|
+
const grace = Number(opts.killGraceMs ?? KILL_GRACE_MS);
|
|
386
|
+
const killGraceMs = Number.isNaN(grace) ? KILL_GRACE_MS : Math.min(Math.max(0, grace), MAX_DELAY_MS - STOP_WAIT_MS);
|
|
384
387
|
let truncated = false;
|
|
385
388
|
const collect = (stream, onChunk) => {
|
|
386
389
|
const chunks = [];
|
|
@@ -489,10 +492,11 @@ function start(file, argv, opts = {}) {
|
|
|
489
492
|
clearTimeout(timer);
|
|
490
493
|
treeStopped = terminateTree(child, signal);
|
|
491
494
|
closeInput();
|
|
495
|
+
const grace2 = signal === "SIGTERM" ? killGraceMs : 0;
|
|
492
496
|
if (signal === "SIGTERM") {
|
|
493
497
|
escalation = setTimeout(() => {
|
|
494
498
|
treeStopped = terminateTree(child, "SIGKILL");
|
|
495
|
-
},
|
|
499
|
+
}, grace2);
|
|
496
500
|
}
|
|
497
501
|
deadline = setTimeout(() => {
|
|
498
502
|
treeStopped = terminateTree(child, "SIGKILL");
|
|
@@ -504,7 +508,7 @@ function start(file, argv, opts = {}) {
|
|
|
504
508
|
}
|
|
505
509
|
}
|
|
506
510
|
void finish(child.exitCode, child.signalCode);
|
|
507
|
-
}, STOP_WAIT_MS);
|
|
511
|
+
}, grace2 + STOP_WAIT_MS);
|
|
508
512
|
};
|
|
509
513
|
const abort = () => stop("SIGTERM");
|
|
510
514
|
const inputError = (err) => {
|
|
@@ -525,7 +529,7 @@ function start(file, argv, opts = {}) {
|
|
|
525
529
|
});
|
|
526
530
|
timer = opts.timeoutMs ? setTimeout(() => {
|
|
527
531
|
timedOut = true;
|
|
528
|
-
stop("
|
|
532
|
+
stop("SIGTERM");
|
|
529
533
|
}, opts.timeoutMs) : void 0;
|
|
530
534
|
opts.signal?.addEventListener("abort", abort, { once: true });
|
|
531
535
|
if (opts.stdin !== void 0 && child.stdin) {
|
|
@@ -646,6 +650,7 @@ async function runScriptFunction(fn, opts) {
|
|
|
646
650
|
cwd: opts.cwd,
|
|
647
651
|
env: opts.env,
|
|
648
652
|
timeoutMs: opts.timeoutMs,
|
|
653
|
+
killGraceMs: opts.killGraceMs,
|
|
649
654
|
signal: opts.signal,
|
|
650
655
|
onStderr: opts.onStderr,
|
|
651
656
|
stdin: stdinPath ? (0, import_node_fs4.createReadStream)(stdinPath) : void 0,
|
package/dist/functions.d.ts
CHANGED
|
@@ -83,6 +83,7 @@ export declare function parseRoleJson(text: string | undefined): unknown;
|
|
|
83
83
|
*/
|
|
84
84
|
export declare function runScriptFunction(fn: ResolvedFunction, opts: CommandOptions & {
|
|
85
85
|
timeoutMs?: number;
|
|
86
|
+
/** How long a stopped tool (abort or timeout) has after SIGTERM before SIGKILL; default 200. */ killGraceMs?: number;
|
|
86
87
|
/** Environment supplied to the process or read for option defaults. */ env?: NodeJS.ProcessEnv;
|
|
87
88
|
/** Working directory used to resolve command-line paths and execute tools. */ cwd?: string;
|
|
88
89
|
/** AbortSignal used to cancel execution and terminate the tool process tree. */ signal?: AbortSignal;
|
package/dist/functions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":"AASA,OAAO,EAAsG,KAAK,SAAS,EAAE,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAI/J,OAAO,EAA4D,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAC/G,OAAO,EAAwD,KAAK,IAAI,EAAE,MAAM,WAAW,CAAC;AAS5F;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,8EAA8E;IAAC,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IAAC,OAAO,CAAC,EAAE,CAA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H,wBAAsB,iBAAiB,CACrC,EAAE,EAAE,gBAAgB,EACpB,IAAI,EAAE,cAAc,GAAG;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gGAAgG,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IACtH,uEAAuE,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IAChG,8EAA8E,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAC5F,gFAAgF,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IACtG,4CAA4C,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAChF,wFAAwF,CAAC,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IAChJ,+DAA+D,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAChG,GACA,OAAO,CAAC,WAAW,CAAC,CAqCtB;AAED,+EAA+E;AAC/E,wBAAgB,iBAAiB,CAAC,CAAC,EAAE;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,EAAE,EAAE,gBAAgB,CAAC;IACrB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,wFAAwF;IACxF,OAAO,EAAE,eAAe,CAAC;IACzB,GAAG,EAAE,MAAM,CAAC;CACb,GAAG,IAAI,CAYP"}
|
package/dist/functions.js
CHANGED
|
@@ -123,7 +123,7 @@ export async function runScriptFunction(fn, opts) {
|
|
|
123
123
|
log: { onLine: opts.onLog },
|
|
124
124
|
};
|
|
125
125
|
const started = start(file, argv, {
|
|
126
|
-
cwd: opts.cwd, env: opts.env, timeoutMs: opts.timeoutMs, signal: opts.signal, onStderr: opts.onStderr,
|
|
126
|
+
cwd: opts.cwd, env: opts.env, timeoutMs: opts.timeoutMs, killGraceMs: opts.killGraceMs, signal: opts.signal, onStderr: opts.onStderr,
|
|
127
127
|
stdin: stdinPath ? createReadStream(stdinPath) : undefined,
|
|
128
128
|
stdout: stdoutPath ? 'stream' : 'text',
|
|
129
129
|
roles: declaredRoles({ schema }, roles),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clyops-jobs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Run clyops tools as jobs: config-bound functions, templated invocation, artifacts, job records and a queue.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"typescript": "^5.6.0"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"clyops-tools": "0.
|
|
41
|
+
"clyops-tools": "0.7.0"
|
|
42
42
|
},
|
|
43
43
|
"homepage": "https://clyops.io/node-tools.html",
|
|
44
44
|
"scripts": {
|
package/src/functions.ts
CHANGED
|
@@ -162,6 +162,7 @@ export async function runScriptFunction(
|
|
|
162
162
|
fn: ResolvedFunction,
|
|
163
163
|
opts: CommandOptions & {
|
|
164
164
|
timeoutMs?: number;
|
|
165
|
+
/** How long a stopped tool (abort or timeout) has after SIGTERM before SIGKILL; default 200. */ killGraceMs?: number;
|
|
165
166
|
/** Environment supplied to the process or read for option defaults. */ env?: NodeJS.ProcessEnv;
|
|
166
167
|
/** Working directory used to resolve command-line paths and execute tools. */ cwd?: string;
|
|
167
168
|
/** AbortSignal used to cancel execution and terminate the tool process tree. */ signal?: AbortSignal;
|
|
@@ -193,7 +194,7 @@ export async function runScriptFunction(
|
|
|
193
194
|
log: { onLine: opts.onLog },
|
|
194
195
|
};
|
|
195
196
|
const started = start(file, argv, {
|
|
196
|
-
cwd: opts.cwd, env: opts.env, timeoutMs: opts.timeoutMs, signal: opts.signal, onStderr: opts.onStderr,
|
|
197
|
+
cwd: opts.cwd, env: opts.env, timeoutMs: opts.timeoutMs, killGraceMs: opts.killGraceMs, signal: opts.signal, onStderr: opts.onStderr,
|
|
197
198
|
stdin: stdinPath ? createReadStream(stdinPath) : undefined,
|
|
198
199
|
stdout: stdoutPath ? 'stream' : 'text',
|
|
199
200
|
roles: declaredRoles({ schema }, roles),
|