deployontime 0.0.0-stage → 0.1.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/LICENSE +661 -0
- package/README.md +259 -2
- package/SECURITY.md +61 -0
- package/mcp/jobs.mjs +137 -0
- package/mcp/runner.mjs +64 -0
- package/mcp/server.mjs +209 -0
- package/mcp/tools.mjs +380 -0
- package/package.json +47 -4
- package/queue/README.md +880 -0
- package/queue/args.mjs +136 -0
- package/queue/cli.mjs +207 -0
- package/queue/clock.mjs +49 -0
- package/queue/commands.mjs +35 -0
- package/queue/failstop.mjs +45 -0
- package/queue/files.mjs +71 -0
- package/queue/fingerprint.mjs +63 -0
- package/queue/gate.mjs +37 -0
- package/queue/git.mjs +61 -0
- package/queue/health.mjs +154 -0
- package/queue/idle.mjs +63 -0
- package/queue/job-wrapper.mjs +116 -0
- package/queue/journal.mjs +216 -0
- package/queue/kinds.mjs +95 -0
- package/queue/limits.mjs +79 -0
- package/queue/linux.mjs +72 -0
- package/queue/nested.mjs +83 -0
- package/queue/notices.mjs +114 -0
- package/queue/notify.mjs +47 -0
- package/queue/probes.mjs +162 -0
- package/queue/proctree.mjs +124 -0
- package/queue/project.mjs +26 -0
- package/queue/ps.mjs +54 -0
- package/queue/reaper.mjs +278 -0
- package/queue/run.mjs +612 -0
- package/queue/schedule-check.mjs +177 -0
- package/queue/settings.mjs +145 -0
- package/queue/setup.mjs +270 -0
- package/queue/slots.mjs +144 -0
- package/queue/stats.mjs +8 -0
- package/queue/stray.mjs +38 -0
- package/queue/timer.mjs +47 -0
- package/queue/units.mjs +8 -0
package/queue/args.mjs
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// The command line of dotime-queue: the flags each subcommand accepts, reading their values, and the usage text.
|
|
2
|
+
// Anything else on the command line, in front of the `--` for `run`, is refused with a usage error, so a misspelled
|
|
3
|
+
// flag never changes what a command does without a word.
|
|
4
|
+
import { UNLABELLED } from "./kinds.mjs";
|
|
5
|
+
|
|
6
|
+
export const USAGE = [
|
|
7
|
+
"dotime-queue: one shared queue for heavy jobs on this computer",
|
|
8
|
+
"",
|
|
9
|
+
' dotime-queue run --label "<project>: <task>" [options] -- <command> [args]',
|
|
10
|
+
" --max-wait <min> leave the line after this many minutes (0: wait without limit)",
|
|
11
|
+
" --max-run <min> run limit for this job",
|
|
12
|
+
" --kind <name> job kind, in place of the guessed one",
|
|
13
|
+
' --after-fix "<note>" run a check that failed twice on unchanged code',
|
|
14
|
+
" --priority join the line at the front",
|
|
15
|
+
" --no-skip run a test or lint check that already passed on this commit",
|
|
16
|
+
" dotime-queue status",
|
|
17
|
+
" dotime-queue passed [--match <text>] [--cwd <dir>]",
|
|
18
|
+
" dotime-queue history [--days <n> | --day <YYYY-MM-DD>]",
|
|
19
|
+
" dotime-queue setup [--write] [--cwd <dir>] [--mcp]",
|
|
20
|
+
" --write add the queue instruction to the agent files (without it: only show)",
|
|
21
|
+
" --cwd <dir> the project folder, in place of the top of the git repository",
|
|
22
|
+
" --mcp also print the MCP client settings for dotime-mcp",
|
|
23
|
+
" dotime-queue help",
|
|
24
|
+
].join("\n");
|
|
25
|
+
|
|
26
|
+
/** text as one shell word: as it is when it holds only characters a shell leaves alone, else in single quotes. */
|
|
27
|
+
export function shellWord(text) {
|
|
28
|
+
if (/^[\w@%+=:,./-]+$/.test(text)) return text;
|
|
29
|
+
return `'${text.replaceAll("'", "'\\''")}'`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Per subcommand: flags that take a value, and flags that stand alone. */
|
|
33
|
+
export const FLAGS = Object.freeze({
|
|
34
|
+
run: { values: ["--label", "--max-wait", "--max-run", "--kind", "--after-fix"], switches: ["--priority", "--no-skip"] },
|
|
35
|
+
status: { values: [], switches: [] },
|
|
36
|
+
passed: { values: ["--match", "--cwd"], switches: [] },
|
|
37
|
+
history: { values: ["--days", "--day"], switches: [] },
|
|
38
|
+
setup: { values: ["--cwd"], switches: ["--write", "--mcp"] },
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
/** The flags of the two scripts that run beside the queue, which take switches only. */
|
|
42
|
+
export const SCRIPT_FLAGS = Object.freeze({
|
|
43
|
+
"reaper": { values: [], switches: ["--dry"] },
|
|
44
|
+
"schedule-check": { values: [], switches: ["--dry", "--json"] },
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
/** The usage exit code, the same for dotime-queue and the scripts. */
|
|
48
|
+
export const USAGE_EXIT = 2;
|
|
49
|
+
|
|
50
|
+
/** null when every word fits the subcommand's flags, else the message to print. args[0] is the subcommand; for
|
|
51
|
+
* `run` only the words in front of "--" are looked at. A value may not be empty, and no flag may be given twice.
|
|
52
|
+
* A value that starts with "--" is taken only in the --name=value spelling: in the other one it is read as the
|
|
53
|
+
* next flag, and the message says how to write it. */
|
|
54
|
+
export function flagError(args, table = FLAGS) {
|
|
55
|
+
const allowed = table[args[0]];
|
|
56
|
+
if (!allowed) return null;
|
|
57
|
+
const cut = args.indexOf("--");
|
|
58
|
+
const words = args.slice(1, args[0] === "run" && cut >= 0 ? cut : args.length);
|
|
59
|
+
const seen = new Set();
|
|
60
|
+
for (let i = 0; i < words.length; i++) {
|
|
61
|
+
const word = words[i];
|
|
62
|
+
const eq = word.indexOf("=");
|
|
63
|
+
const name = eq < 0 ? word : word.slice(0, eq);
|
|
64
|
+
const known = allowed.values.includes(name) || allowed.switches.includes(name);
|
|
65
|
+
if (known && seen.has(name)) return `option ${name} is given twice`;
|
|
66
|
+
seen.add(name);
|
|
67
|
+
if (allowed.values.includes(name)) {
|
|
68
|
+
const joined = eq >= 0;
|
|
69
|
+
const value = joined ? word.slice(eq + 1) : words[++i];
|
|
70
|
+
if (value === undefined || value === "") return `option ${name} needs a value`;
|
|
71
|
+
if (!joined && value.startsWith("--")) {
|
|
72
|
+
const example = `${name}=${shellWord(value)}`;
|
|
73
|
+
return `option ${name} needs a value; give ${name} a value, or for the value "${value}" write ${example}`;
|
|
74
|
+
}
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (allowed.switches.includes(word)) continue;
|
|
78
|
+
if (allowed.switches.includes(name)) return `option ${name} takes no value`;
|
|
79
|
+
return word.startsWith("-") ? `unknown option ${name}` : `unexpected word "${word}"`;
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// The words in front of "--": a flag behind it belongs to the job's command.
|
|
85
|
+
const flagWords = (args) => {
|
|
86
|
+
const cut = args.indexOf("--");
|
|
87
|
+
return cut < 0 ? args : args.slice(0, cut);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/** The value of --name <value> or --name=<value> among the flags in front of "--"; undefined when absent. */
|
|
91
|
+
export function opt(args, name) {
|
|
92
|
+
const flags = flagWords(args);
|
|
93
|
+
const joined = flags.find((a) => a.startsWith(`${name}=`));
|
|
94
|
+
const at = flags.indexOf(name);
|
|
95
|
+
if (joined) return joined.slice(name.length + 1);
|
|
96
|
+
return at >= 0 ? flags[at + 1] : undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** --max-run in minutes: null when absent, NaN when it is not a number above 0. */
|
|
100
|
+
export function parseMaxRun(args) {
|
|
101
|
+
const raw = opt(args, "--max-run");
|
|
102
|
+
if (raw === undefined) return null;
|
|
103
|
+
const value = Number(raw);
|
|
104
|
+
return raw !== "" && Number.isFinite(value) && value > 0 ? value : NaN;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** --max-wait in minutes: the fallback when absent, null when it has no value or is not a number of 0 or more. */
|
|
108
|
+
export function parseMaxWait(args, fallback) {
|
|
109
|
+
const raw = opt(args, "--max-wait");
|
|
110
|
+
if (raw === undefined) return flagWords(args).includes("--max-wait") ? null : fallback;
|
|
111
|
+
const minutes = Number(raw);
|
|
112
|
+
return raw !== "" && Number.isFinite(minutes) && minutes >= 0 ? minutes : null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Reads the words of `run`. Returns { label, cmd, priority, noSkip, maxWait, maxRun, kind, afterFix }, or { error }
|
|
116
|
+
* with the text to print. settings.maxWaitMin is the wait limit without --max-wait. */
|
|
117
|
+
export function parseRunArgs(args, settings) {
|
|
118
|
+
const cut = args.indexOf("--");
|
|
119
|
+
if (args[0] !== "run" || cut < 0 || cut === args.length - 1) return { error: USAGE };
|
|
120
|
+
const badFlag = flagError(args);
|
|
121
|
+
if (badFlag) return { error: badFlag };
|
|
122
|
+
const maxWait = parseMaxWait(args, settings.maxWaitMin);
|
|
123
|
+
if (maxWait === null) return { error: "--max-wait wants a number of minutes, 0 or more; 0 means no limit" };
|
|
124
|
+
const maxRun = parseMaxRun(args);
|
|
125
|
+
if (Number.isNaN(maxRun)) return { error: "--max-run wants a positive number of minutes" };
|
|
126
|
+
return {
|
|
127
|
+
label: opt(args, "--label")?.trim() || UNLABELLED,
|
|
128
|
+
cmd: args.slice(cut + 1),
|
|
129
|
+
priority: flagWords(args).includes("--priority"),
|
|
130
|
+
noSkip: flagWords(args).includes("--no-skip"),
|
|
131
|
+
maxWait,
|
|
132
|
+
maxRun,
|
|
133
|
+
kind: opt(args, "--kind"),
|
|
134
|
+
afterFix: opt(args, "--after-fix")?.trim() || null,
|
|
135
|
+
};
|
|
136
|
+
}
|
package/queue/cli.mjs
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The dotime-queue command. `run` waits for a slot and runs one job under a run limit; `status` shows slots, line
|
|
3
|
+
// and gate; `passed` looks up a pass stamp; `history` sums up the journal; `setup` puts the queue instruction into a
|
|
4
|
+
// project's agent files. queue/README.md describes each in full.
|
|
5
|
+
import { isMainModule, loadSettings, paths, timeZone } from "./settings.mjs";
|
|
6
|
+
import { minutesSince } from "./clock.mjs";
|
|
7
|
+
import { snapshot } from "./slots.mjs";
|
|
8
|
+
import { gateReason } from "./gate.mjs";
|
|
9
|
+
import { cachedHealth, healthVerdict, readHealth, savedCpuTimes } from "./health.mjs";
|
|
10
|
+
import { gitState, isRepository, repoTop } from "./git.mjs";
|
|
11
|
+
import { findStamp, historyWindow, readLines, summarize } from "./journal.mjs";
|
|
12
|
+
import { notify } from "./notify.mjs";
|
|
13
|
+
import { markerOf } from "./nested.mjs";
|
|
14
|
+
import { folderProject } from "./project.mjs";
|
|
15
|
+
import { flagError, opt, USAGE } from "./args.mjs";
|
|
16
|
+
import { applyPlan, blockText, mcpLines, planFolder } from "./setup.mjs";
|
|
17
|
+
import { EXIT, jobFolder, realDeps, runCommand } from "./run.mjs";
|
|
18
|
+
import { afterMinutes } from "./timer.mjs";
|
|
19
|
+
import { MINUTE } from "./units.mjs";
|
|
20
|
+
|
|
21
|
+
// A nested run belongs to a job only when it names that job's slot or note, pid and start time: a later job in the
|
|
22
|
+
// same slot is another job.
|
|
23
|
+
const insideOf = (entry, h) => !!h.file && entry.outer === markerOf(h.file) && entry.outerPid === h.pid
|
|
24
|
+
&& entry.outerBorn === h.born;
|
|
25
|
+
|
|
26
|
+
/** The lines `status` prints. gate: the reason the gate is shut, or "". nested: the nested runs, each shown under the
|
|
27
|
+
* job whose slot or note, pid and start time it names in outer, outerPid and outerBorn, so a nested run inside a
|
|
28
|
+
* nested run is shown one step further in; they hold no slot and are not counted. One that waits for a place under
|
|
29
|
+
* its parent says so; its minutes count from when it began to wait, and once it runs, from when it started. */
|
|
30
|
+
export function statusLines({ holders, queue, nested = [], gate, max, now = Date.now() }) {
|
|
31
|
+
const lines = [`slots: ${holders.length} of ${max} taken, ${queue.length} waiting`];
|
|
32
|
+
for (const h of holders) {
|
|
33
|
+
const began = h.startedAt ?? h.at;
|
|
34
|
+
const ranMin = (now - began) / MINUTE;
|
|
35
|
+
const facts = [`pid ${h.pid}`];
|
|
36
|
+
if (h.kind) facts.push(`kind ${h.kind}`);
|
|
37
|
+
facts.push(`${minutesSince(began, now)} min so far`);
|
|
38
|
+
if (h.limitMin == null) facts.push("limit unknown");
|
|
39
|
+
else {
|
|
40
|
+
facts.push(`limit ${h.limitMin} min`);
|
|
41
|
+
if (h.priority) facts.push(`priority (warning at ${h.limitMin} min, stop at ${h.killMin} min)`);
|
|
42
|
+
facts.push(`${Math.max(0, Math.round((h.killMin ?? h.limitMin) - ranMin))} min left`);
|
|
43
|
+
if (h.longRunMin && ranMin > h.longRunMin) facts.push(`past the ${h.longRunMin} min long-run mark`);
|
|
44
|
+
}
|
|
45
|
+
lines.push(`running "${h.label}": ${facts.join(", ")}`);
|
|
46
|
+
nestedLines(h, nested, now, 1, lines);
|
|
47
|
+
}
|
|
48
|
+
queue.forEach((q, i) => {
|
|
49
|
+
const priority = q.priority ? ", priority" : "";
|
|
50
|
+
lines.push(`waiting ${i + 1} "${q.label}": pid ${q.pid}, ${minutesSince(q.at, now)} min so far${priority}`);
|
|
51
|
+
});
|
|
52
|
+
lines.push(gate ? `gate: shut; ${gate}` : "gate: open");
|
|
53
|
+
return lines;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// The nested runs inside parent, each followed by its own, depth steps in. A run is shown once at most.
|
|
57
|
+
function nestedLines(parent, nested, now, depth, lines, shown = new Set()) {
|
|
58
|
+
for (const n of nested.filter((entry) => insideOf(entry, parent) && !shown.has(entry))) {
|
|
59
|
+
shown.add(n);
|
|
60
|
+
const ran = `${minutesSince(n.startedAt ?? n.at, now)} min so far`;
|
|
61
|
+
const state = n.waiting ? `waiting for a nested place under "${parent.label}"` : "no slot of its own";
|
|
62
|
+
lines.push(`${" ".repeat(depth)}nested "${n.label}": pid ${n.pid}, ${ran}, ${state}`);
|
|
63
|
+
nestedLines(n, nested, now, depth + 1, lines, shown);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** One line of `history` for a project's totals. Skipped jobs are named only when there are any, with the run time
|
|
68
|
+
* of the passing runs they relied on as the time saved. */
|
|
69
|
+
export function historyRow(name, t) {
|
|
70
|
+
const gates = Object.entries(t.waitBy).map(([gate, min]) => `${gate} ${min} min`).join(", ") || "nothing";
|
|
71
|
+
const skipped = t.skipped ? `, skipped ${t.skipped} (saved ${t.savedMin} min)` : "";
|
|
72
|
+
return `${name}: jobs ${t.jobs}, failed ${t.failed}, stopped ${t.stopped}, timed out ${t.timedOut}, `
|
|
73
|
+
+ `refused ${t.refused}, gave up ${t.gaveUp}${skipped}; `
|
|
74
|
+
+ `waited: jobs ${t.waited}, sum ${t.waitMinTotal} min, clock ${t.waitWallMin} min, `
|
|
75
|
+
+ `clock with no job running ${t.blockedOnlyMin} min, `
|
|
76
|
+
+ `median ${t.waitMedian} min, p90 ${t.waitP90} min; held by: ${gates}`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const say = (text) => process.stderr.write(`dotime-queue: ${text}\n`);
|
|
80
|
+
|
|
81
|
+
/** Prints `status` and returns 0. deps: { readHealth, print }; readHealth is handed { limits }, as for `run`, and
|
|
82
|
+
* the CPU times saved with the shared reading as cpuSince, which status reads but never writes. */
|
|
83
|
+
export function cmdStatus({ settings, files }, { readHealth: read = readHealth, print = console.log } = {}) {
|
|
84
|
+
const { holders, queue, nested } = snapshot({ dirs: files });
|
|
85
|
+
const cpuSince = savedCpuTimes(files.healthCache);
|
|
86
|
+
const health = healthVerdict(read({ limits: settings.health, cpuSince }), settings.health);
|
|
87
|
+
const gate = gateReason({ holders, health }, settings.slots);
|
|
88
|
+
for (const line of statusLines({ holders, queue, nested, gate, max: settings.slots })) print(line);
|
|
89
|
+
return 0;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Prints the pass stamp of the folder in --cwd, else of the current folder, and returns 0, or 1 when there is none.
|
|
93
|
+
* A current folder that was removed is a usage error, with a line that points to --cwd. */
|
|
94
|
+
function cmdPassed(args, { files, tz }) {
|
|
95
|
+
const read = jobFolder({ cwd: opt(args, "--cwd") || undefined }, { cwd: () => process.cwd() });
|
|
96
|
+
if (read.error) {
|
|
97
|
+
say("the current folder was removed; run passed from a folder that exists, or name one with --cwd <dir>");
|
|
98
|
+
return EXIT.usage;
|
|
99
|
+
}
|
|
100
|
+
const { cwd } = read;
|
|
101
|
+
const commit = gitState(cwd);
|
|
102
|
+
const folder = { project: folderProject(cwd), ...commit, repository: commit.head !== null || isRepository(cwd) };
|
|
103
|
+
const found = findStamp(readLines(files.journal), folder, opt(args, "--match") || "", { tz });
|
|
104
|
+
console.log(found.text);
|
|
105
|
+
return found.stamp ? 0 : 1;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function cmdHistory(args, { files, tz }) {
|
|
109
|
+
const day = opt(args, "--day");
|
|
110
|
+
const daysText = opt(args, "--days");
|
|
111
|
+
if (day !== undefined && !/^\d{4}-\d{2}-\d{2}$/.test(day)) {
|
|
112
|
+
say("--day: needs a date as YYYY-MM-DD");
|
|
113
|
+
return EXIT.usage;
|
|
114
|
+
}
|
|
115
|
+
if (daysText !== undefined && !/^[1-9]\d*$/.test(daysText)) {
|
|
116
|
+
say("--days: needs a whole number of days, 1 or more");
|
|
117
|
+
return EXIT.usage;
|
|
118
|
+
}
|
|
119
|
+
const range = historyWindow({ day, days: daysText === undefined ? 7 : Number(daysText), tz });
|
|
120
|
+
const { all, byProject } = summarize(readLines(files.journal), range.from, range.to);
|
|
121
|
+
console.log(`history: ${range.title}, jobs ${all.jobs}`);
|
|
122
|
+
if (!all.jobs) return 0;
|
|
123
|
+
for (const [name, t] of [["all projects", all], ...Object.entries(byProject)]) console.log(historyRow(name, t));
|
|
124
|
+
return 0;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** `setup`: shows, or with --write makes, the changes to the project's agent files, then with --mcp prints the MCP
|
|
128
|
+
* settings. Without --cwd the project folder is the top folder of the git repository the current folder is in, or
|
|
129
|
+
* the current folder outside git. Exits 0 when done, 1 when a file cannot be read or written (nothing is written
|
|
130
|
+
* then, unless a write itself fails part way, which it names), 2 when the folder in --cwd does not exist. */
|
|
131
|
+
export function cmdSetup(args, {
|
|
132
|
+
cwd = () => process.cwd(), top = repoTop, print = console.log, warn = say, writeFile,
|
|
133
|
+
} = {}) {
|
|
134
|
+
const write = args.includes("--write");
|
|
135
|
+
const named = opt(args, "--cwd");
|
|
136
|
+
let dir = named, where = "";
|
|
137
|
+
if (dir === undefined) {
|
|
138
|
+
try {
|
|
139
|
+
dir = cwd();
|
|
140
|
+
} catch {
|
|
141
|
+
warn("the current folder was removed; run setup from a folder that exists, or name one with --cwd <dir>");
|
|
142
|
+
return EXIT.usage;
|
|
143
|
+
}
|
|
144
|
+
const repo = top(dir);
|
|
145
|
+
where = repo ? " (the top folder of the git repository)" : " (the current folder, which is not in git)";
|
|
146
|
+
dir = repo ?? dir;
|
|
147
|
+
}
|
|
148
|
+
const plan = planFolder(dir);
|
|
149
|
+
if (plan.error) {
|
|
150
|
+
warn(`setup: ${plan.error}`);
|
|
151
|
+
return plan.folder ? EXIT.usage : 1;
|
|
152
|
+
}
|
|
153
|
+
print(`setup: project folder ${plan.root}${where}`);
|
|
154
|
+
const done = applyPlan(plan, { write, ...(writeFile ? { writeFile } : {}) });
|
|
155
|
+
for (const line of done.lines) print(line);
|
|
156
|
+
for (const line of plan.notes ?? []) print(line);
|
|
157
|
+
if (done.error) {
|
|
158
|
+
print(`changed: ${done.changed.join(", ") || "nothing"}`);
|
|
159
|
+
warn(`setup: ${done.error}`);
|
|
160
|
+
return 1;
|
|
161
|
+
}
|
|
162
|
+
if (write) print(`changed: ${done.changed.join(", ") || "nothing"}`);
|
|
163
|
+
else {
|
|
164
|
+
print("dry run: nothing was changed; add --write to make these changes. The block:");
|
|
165
|
+
for (const line of blockText().split("\n")) print(line);
|
|
166
|
+
}
|
|
167
|
+
if (args.includes("--mcp")) for (const line of ["", ...mcpLines()]) print(line);
|
|
168
|
+
return 0;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Runs one subcommand and resolves with its exit code. Nothing in here or below ends the process: the one call of
|
|
172
|
+
* process.exit() is at the end of this file. */
|
|
173
|
+
export async function main(args = process.argv.slice(2)) {
|
|
174
|
+
if (args[0] === "help" || args[0] === "--help") {
|
|
175
|
+
console.log(USAGE);
|
|
176
|
+
return 0;
|
|
177
|
+
}
|
|
178
|
+
const command = args.length ? args[0] : "status";
|
|
179
|
+
const badFlag = command === "run" ? null : flagError([command, ...args.slice(1)]);
|
|
180
|
+
if (badFlag) {
|
|
181
|
+
say(badFlag);
|
|
182
|
+
return EXIT.usage;
|
|
183
|
+
}
|
|
184
|
+
// setup reads no settings and never touches the state folder.
|
|
185
|
+
if (command === "setup") return cmdSetup(args);
|
|
186
|
+
// The settings, the state folder and the zone are read once here and handed to the command. The current folder
|
|
187
|
+
// is read only by the commands that use it, so status and history still work in a folder that was removed, and
|
|
188
|
+
// `run` reads it only after its arguments were found valid.
|
|
189
|
+
const ctx = { settings: loadSettings(), files: paths(), tz: timeZone() };
|
|
190
|
+
if (command === "status") return cmdStatus(ctx);
|
|
191
|
+
if (command === "passed") return cmdPassed(args, ctx);
|
|
192
|
+
if (command === "history") return cmdHistory(args, ctx);
|
|
193
|
+
return runCommand(args, ctx, runDeps(ctx));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** The deps `run` uses. Its health reading is shared between jobs that wait at the same time, one per poll, and is
|
|
197
|
+
* taken with the gate limits, as for `status`. read: the reading behind the shared one. */
|
|
198
|
+
export function runDeps({ settings, files }, read = readHealth) {
|
|
199
|
+
const readGateHealth = (options) => read({ ...options, limits: settings.health });
|
|
200
|
+
return realDeps({
|
|
201
|
+
readHealth: () => cachedHealth(files.healthCache, settings.pollMs, readGateHealth),
|
|
202
|
+
notify: (title, message) => notify(title, message, { env: process.env, logFile: files.notifyLog }),
|
|
203
|
+
after: afterMinutes,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (isMainModule(import.meta.url)) process.exit(await main());
|
package/queue/clock.mjs
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Clock helpers. Times shown to people use a 24-hour clock in the configured zone, and calendar days are counted in
|
|
2
|
+
// that zone too.
|
|
3
|
+
import { MINUTE } from "./units.mjs";
|
|
4
|
+
|
|
5
|
+
function wallParts(ms, zone) {
|
|
6
|
+
const format = new Intl.DateTimeFormat("en-US", {
|
|
7
|
+
timeZone: zone, hourCycle: "h23", timeZoneName: "short",
|
|
8
|
+
year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit",
|
|
9
|
+
});
|
|
10
|
+
return Object.fromEntries(format.formatToParts(ms).map((part) => [part.type, part.value]));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Hours and minutes with the zone name: "HH:MM UTC". */
|
|
14
|
+
export function clockTime(ms, zone = "UTC") {
|
|
15
|
+
const p = wallParts(ms, zone);
|
|
16
|
+
return `${p.hour}:${p.minute} ${p.timeZoneName}`;
|
|
17
|
+
}
|
|
18
|
+
/** Day, hours and minutes with the zone name: "YYYY-MM-DD HH:MM UTC". */
|
|
19
|
+
export function dateTime(ms, zone = "UTC") {
|
|
20
|
+
const p = wallParts(ms, zone);
|
|
21
|
+
return `${p.year}-${p.month}-${p.day} ${p.hour}:${p.minute} ${p.timeZoneName}`;
|
|
22
|
+
}
|
|
23
|
+
/** The calendar day as "YYYY-MM-DD". */
|
|
24
|
+
export function dayOf(ms, zone = "UTC") {
|
|
25
|
+
const p = wallParts(ms, zone);
|
|
26
|
+
return `${p.year}-${p.month}-${p.day}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** A "YYYY-MM-DD" day moved by a number of days. */
|
|
30
|
+
export function shiftDay(day, by) {
|
|
31
|
+
const [year, month, date] = day.split("-").map(Number);
|
|
32
|
+
return new Date(Date.UTC(year, month - 1, date + by)).toISOString().slice(0, 10);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Milliseconds the zone's wall clock is ahead of UTC at a moment. */
|
|
36
|
+
export function zoneOffset(ms, zone = "UTC") {
|
|
37
|
+
const p = wallParts(ms, zone);
|
|
38
|
+
return Date.UTC(+p.year, +p.month - 1, +p.day, +p.hour, +p.minute, +p.second) - Math.floor(ms / 1000) * 1000;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The moment a "YYYY-MM-DD" day begins in the zone. */
|
|
42
|
+
export function dayStart(day, zone = "UTC") {
|
|
43
|
+
const [year, month, date] = day.split("-").map(Number), asUtc = Date.UTC(year, month - 1, date);
|
|
44
|
+
// The offset is looked up twice because it can differ between the first guess and the real midnight.
|
|
45
|
+
const guess = asUtc - zoneOffset(asUtc, zone);
|
|
46
|
+
return asUtc - zoneOffset(guess, zone);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const minutesSince = (then, now = Date.now()) => Math.max(0, Math.round((now - then) / MINUTE));
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// The command-line patterns the queue judges processes and jobs by, kept together so their differences are on
|
|
2
|
+
// purpose. Each answers a different question, so each matches a different set of commands.
|
|
3
|
+
|
|
4
|
+
/** Shells. A shell in front of a command only starts it, so it is looked through: its `-c` text is what runs. */
|
|
5
|
+
export const SHELLS = new Set(["sh", "bash", "zsh"]);
|
|
6
|
+
const SHELL_NAMES = [...SHELLS].join("|");
|
|
7
|
+
|
|
8
|
+
/** A process whose program is a shell, in any folder: "sh -c jest" names a test tool but is only its launcher. */
|
|
9
|
+
export const SHELL_PROGRAM_RE = new RegExp(`^(\\S*\\/)?(${SHELL_NAMES})(\\s|$)`);
|
|
10
|
+
|
|
11
|
+
/** Job kind "test": the words of a label or command that make a test job. Wide on purpose, because a wrong kind
|
|
12
|
+
* only means a less fitting run limit. `node --test` counts. */
|
|
13
|
+
export const TEST_KIND_RE = /\b(tests?|check|suite|spec|e2e|vitest|jest|playwright)\b|node --test/i;
|
|
14
|
+
|
|
15
|
+
/** One-shot test commands: they exit by themselves, so the reaper never takes them for an idle dev server even
|
|
16
|
+
* when they match its server pattern (vitest without "run" is a watcher, jest with --watch too). `node --test`
|
|
17
|
+
* counts. */
|
|
18
|
+
export const TEST_RUN_RE = /\bvitest (--)?run\b|\bnode --test\b|playwright test|jest(?!.*--watch)/;
|
|
19
|
+
|
|
20
|
+
/** Processes of a large test run outside the queue: test runners and their workers, by the names they show in the
|
|
21
|
+
* process table. `node --test` is left out on purpose: the files it runs appear as plain `node <file>` processes
|
|
22
|
+
* that name no test tool, so the size of such a run cannot be read from the table. */
|
|
23
|
+
export const STRAY_TEST_RE = new RegExp([
|
|
24
|
+
"jest-worker", "\\/jest(\\.js)?(\\s|$)", "\\bjest\\s", "\\bvitest(\\.mjs)?(\\s|$)", "vitest\\/dist",
|
|
25
|
+
"playwright test", "@playwright\\/test",
|
|
26
|
+
].join("|"));
|
|
27
|
+
|
|
28
|
+
/** Programs that only start a script, so a dev server's process group may hold them above the server: a package
|
|
29
|
+
* manager or runner (also as the script node runs, as pnpm and yarn appear), or a shell with `-c`. The program
|
|
30
|
+
* itself must be the launcher: a folder named npm further along a command line does not count. */
|
|
31
|
+
export const LAUNCHER_RE = new RegExp([
|
|
32
|
+
"^(\\S*\\/)?(npm|npx|pnpm|yarn|bun)(\\s|$)",
|
|
33
|
+
"^(\\S*\\/)?node \\S*\\/(npm|npx|pnpm|yarn)(-cli)?(\\.c?js)?(\\s|$)",
|
|
34
|
+
`^(\\S*\\/)?(${SHELL_NAMES}) -c `,
|
|
35
|
+
].join("|"));
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// The repeated-failure stop: a run is refused when the same check just failed twice on unchanged code.
|
|
2
|
+
import { clockTime } from "./clock.mjs";
|
|
3
|
+
import { isFailedRun, isStopped, lineProject, parseLines } from "./journal.mjs";
|
|
4
|
+
import { UNLABELLED } from "./kinds.mjs";
|
|
5
|
+
import { HOUR } from "./units.mjs";
|
|
6
|
+
|
|
7
|
+
// A run that ended by itself or at its limit; a stopped run says nothing about the code.
|
|
8
|
+
const countsAsAttempt = (row) => row.outcome === "timed-out" || (row.outcome === "ran" && !isStopped(row));
|
|
9
|
+
const failed = (row) => row.outcome === "timed-out" || isFailedRun(row);
|
|
10
|
+
const bothDiffer = (a, b) => a != null && b != null && a !== b;
|
|
11
|
+
// The journal stores the fingerprint as fp. Lines that call it fingerprint are read as well.
|
|
12
|
+
const printOf = (row) => row.fp ?? row.fingerprint;
|
|
13
|
+
/** Should this run be refused because the same check just failed twice on the same code?
|
|
14
|
+
* job = { label, cmd, project, cwd, head, fingerprint, at }.
|
|
15
|
+
* Returns { refuse: false }, { refuse: false, changed: "commit" | "files" | "command" }, or
|
|
16
|
+
* { refuse: true, reason }. */
|
|
17
|
+
export function failStop(lines, job, limitSettings, tz) {
|
|
18
|
+
// Runs are one check when their labels match; failing that, when command, project and folder all match.
|
|
19
|
+
const sameFolder = (row) => !job.cwd || !row.cwd || row.cwd === job.cwd;
|
|
20
|
+
const sameCheck = (row) => (job.label !== UNLABELLED && row.label === job.label)
|
|
21
|
+
|| (!!job.cmd && row.cmd === job.cmd && lineProject(row) === job.project && sameFolder(row));
|
|
22
|
+
const finished = parseLines(lines)
|
|
23
|
+
.filter((row) => row.endedAt && countsAsAttempt(row) && sameCheck(row))
|
|
24
|
+
.sort((a, b) => Date.parse(b.endedAt) - Date.parse(a.endedAt));
|
|
25
|
+
const [last, previous] = finished;
|
|
26
|
+
if (!last || !previous || !failed(last) || !failed(previous)) return { refuse: false };
|
|
27
|
+
const sincePrevious = (job.at ?? Date.now()) - Date.parse(previous.endedAt);
|
|
28
|
+
if (sincePrevious > limitSettings.failWindowHours * HOUR) return { refuse: false };
|
|
29
|
+
const codeMoved = last.head !== previous.head || bothDiffer(printOf(last), printOf(previous));
|
|
30
|
+
if (codeMoved || bothDiffer(last.cmd, previous.cmd)) return { refuse: false };
|
|
31
|
+
if (last.head !== undefined && last.head !== job.head) return { refuse: false, changed: "commit" };
|
|
32
|
+
if (bothDiffer(printOf(last), job.fingerprint)) return { refuse: false, changed: "files" };
|
|
33
|
+
if (bothDiffer(last.cmd, job.cmd)) return { refuse: false, changed: "command" };
|
|
34
|
+
const ending = (row) => {
|
|
35
|
+
const how = row.outcome === "timed-out" ? "run limit hit" : `exit ${row.exit}`;
|
|
36
|
+
return `${how} at ${clockTime(Date.parse(row.endedAt), tz)}`;
|
|
37
|
+
};
|
|
38
|
+
const commit = last.head ? `, commit ${String(last.head).slice(0, 8)}` : "";
|
|
39
|
+
return {
|
|
40
|
+
refuse: true,
|
|
41
|
+
reason: `same check failed twice on unchanged code: "${job.label}"${commit}, `
|
|
42
|
+
+ `${ending(previous)}, then ${ending(last)}; `
|
|
43
|
+
+ 'hint: change the code, or pass --after-fix "<note>" before the -- to run it anyway',
|
|
44
|
+
};
|
|
45
|
+
}
|
package/queue/files.mjs
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// The file helpers of the modules that keep state on disk: a JSON read that tells a missing file from a broken one,
|
|
2
|
+
// a JSON write that no reader ever sees half done, the removal of temporary files a dead process left behind, and an
|
|
3
|
+
// append that creates the folder first.
|
|
4
|
+
import {
|
|
5
|
+
appendFileSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync,
|
|
6
|
+
} from "node:fs";
|
|
7
|
+
import { basename, dirname, join } from "node:path";
|
|
8
|
+
import { MINUTE } from "./units.mjs";
|
|
9
|
+
|
|
10
|
+
/** How old a temporary file must be before it counts as abandoned by a process that died while writing it. */
|
|
11
|
+
export const STALE_TEMP_MS = MINUTE;
|
|
12
|
+
|
|
13
|
+
/** The name a file is written under before it is moved into place. It does not end in ".json", so a reader that
|
|
14
|
+
* lists entries by that ending skips it. */
|
|
15
|
+
export const tempName = (file) => `${file}.tmp-${process.pid}`;
|
|
16
|
+
|
|
17
|
+
/** Removes a temporary file that is older than STALE_TEMP_MS; a younger one is a write still in progress. */
|
|
18
|
+
export function dropOldTemp(file, now = Date.now()) {
|
|
19
|
+
try {
|
|
20
|
+
if (now - statSync(file).mtimeMs > STALE_TEMP_MS) rmSync(file, { force: true });
|
|
21
|
+
} catch { /* already gone */ }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Removes the abandoned temporary files of one file, the ones tempName() gave it in any process. */
|
|
25
|
+
export function dropOldTemps(file, now = Date.now()) {
|
|
26
|
+
const prefix = `${basename(file)}.tmp-`;
|
|
27
|
+
let names = [];
|
|
28
|
+
try { names = readdirSync(dirname(file)); } catch { return; }
|
|
29
|
+
for (const name of names) if (name.startsWith(prefix)) dropOldTemp(join(dirname(file), name), now);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The parsed content of a JSON file, or fallback when there is none. A missing file is silent. For a file that
|
|
33
|
+
* exists but cannot be read, problem("unreadable", code) is called; for one that is not JSON, problem("invalid"). */
|
|
34
|
+
export function readJson(file, fallback = null, problem = null) {
|
|
35
|
+
let text;
|
|
36
|
+
try {
|
|
37
|
+
text = readFileSync(file, "utf8");
|
|
38
|
+
} catch (e) {
|
|
39
|
+
if (e.code !== "ENOENT") problem?.("unreadable", e.code ?? e.message);
|
|
40
|
+
return fallback;
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
return JSON.parse(text);
|
|
44
|
+
} catch {
|
|
45
|
+
problem?.("invalid");
|
|
46
|
+
return fallback;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Writes JSON under a temporary name and then moves it into place, creating the folder first. Throws when the
|
|
51
|
+
* file cannot be written; the temporary file is removed again in that case. */
|
|
52
|
+
export function writeJsonAtomic(file, value, space = undefined) {
|
|
53
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
54
|
+
const temp = tempName(file);
|
|
55
|
+
try {
|
|
56
|
+
writeFileSync(temp, JSON.stringify(value, null, space));
|
|
57
|
+
renameSync(temp, file);
|
|
58
|
+
} catch (e) {
|
|
59
|
+
rmSync(temp, { force: true });
|
|
60
|
+
throw e;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Appends text to a file, creating its folder first. Returns false, without throwing, when that fails. */
|
|
65
|
+
export function appendLine(file, text) {
|
|
66
|
+
try {
|
|
67
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
68
|
+
appendFileSync(file, text);
|
|
69
|
+
return true;
|
|
70
|
+
} catch { return false; }
|
|
71
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// The code fingerprint: a hash that moves when the code under test moves. It runs read-only git commands and reads
|
|
2
|
+
// files, and is what the repeated-failure stop compares between runs.
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { readFileSync, statSync } from "node:fs";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { git } from "./git.mjs";
|
|
7
|
+
|
|
8
|
+
// A hash that moves when the code under test moves. Tracked files always count. Small untracked files are hashed
|
|
9
|
+
// whole, big ones as size plus modification time. Untracked files in output folders, and untracked media, archive
|
|
10
|
+
// and log files, stay out of it: a check rewrites those on every run.
|
|
11
|
+
|
|
12
|
+
export const UNTRACKED = { maxFileBytes: 1024 * 1024, maxFiles: 2000, maxTotalBytes: 32 * 1024 * 1024 };
|
|
13
|
+
const SKIPPED_UNTRACKED_RE = /\.(png|jpe?g|gif|webp|avif|ico|bmp|mp4|webm|mov|pdf|zip|t?gz|log)$/i;
|
|
14
|
+
const SCRIPT_MAX_BYTES = 4 * 1024 * 1024;
|
|
15
|
+
|
|
16
|
+
function addUntracked(hash, cwd, ignoreDirs) {
|
|
17
|
+
const top = git(cwd, ["rev-parse", "--show-toplevel"])?.trim();
|
|
18
|
+
if (!top) return;
|
|
19
|
+
const excludes = ignoreDirs.map((dir) => `:(top,exclude,glob)**/${dir}/**`);
|
|
20
|
+
const listArgs = ["ls-files", "-o", "--exclude-standard", "-z", "--", ".", ...excludes];
|
|
21
|
+
const listed = git(top, listArgs, { timeout: 15_000, maxBuffer: 64 * 1024 * 1024 });
|
|
22
|
+
if (listed === null) {
|
|
23
|
+
hash.update("untracked-unknown");
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const counted = (name) => name && !SKIPPED_UNTRACKED_RE.test(name);
|
|
27
|
+
const files = listed.split("\0").filter(counted).sort().slice(0, UNTRACKED.maxFiles);
|
|
28
|
+
let bytesRead = 0;
|
|
29
|
+
for (const name of files) {
|
|
30
|
+
try {
|
|
31
|
+
const path = join(top, name);
|
|
32
|
+
const info = statSync(path);
|
|
33
|
+
if (!info.isFile()) continue;
|
|
34
|
+
hash.update(`\0${name}\0`);
|
|
35
|
+
const whole = info.size <= UNTRACKED.maxFileBytes && bytesRead + info.size <= UNTRACKED.maxTotalBytes;
|
|
36
|
+
if (whole) {
|
|
37
|
+
hash.update(readFileSync(path));
|
|
38
|
+
bytesRead += info.size;
|
|
39
|
+
} else hash.update(`${info.size}:${info.mtimeMs}`);
|
|
40
|
+
} catch { /* the file went away */ }
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** A short hash over uncommitted changes, untracked files and any file named in the command. ignoreDirs: the
|
|
44
|
+
* outputDirs setting. Never throws. */
|
|
45
|
+
export function fingerprint(cwd, command, ignoreDirs) {
|
|
46
|
+
const hash = createHash("sha1");
|
|
47
|
+
try {
|
|
48
|
+
// --no-ext-diff --no-textconv: a diff program configured in the repository is never started by the queue
|
|
49
|
+
for (const args of [["status", "--porcelain"], ["diff", "--no-ext-diff", "--no-textconv", "HEAD"]]) {
|
|
50
|
+
const out = git(cwd, args, { encoding: "buffer", timeout: 15_000, maxBuffer: 256 * 1024 * 1024 });
|
|
51
|
+
hash.update(out ?? Buffer.from("git-unknown"));
|
|
52
|
+
}
|
|
53
|
+
addUntracked(hash, cwd, ignoreDirs);
|
|
54
|
+
} catch { hash.update("git-unknown"); }
|
|
55
|
+
for (const arg of command) {
|
|
56
|
+
try {
|
|
57
|
+
const path = arg.startsWith("/") ? arg : join(cwd, arg);
|
|
58
|
+
const info = statSync(path);
|
|
59
|
+
if (info.isFile() && info.size < SCRIPT_MAX_BYTES) hash.update(readFileSync(path));
|
|
60
|
+
} catch { /* not a file */ }
|
|
61
|
+
}
|
|
62
|
+
return hash.digest("hex").slice(0, 16);
|
|
63
|
+
}
|
package/queue/gate.mjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// The gate policy: who may take a free slot, what keeps a waiting job out, and when a waiting job gives up. It only
|
|
2
|
+
// judges the slots, the line and a health verdict it is handed; slots.mjs keeps the files. max is the slot count.
|
|
3
|
+
import { MINUTE } from "./units.mjs";
|
|
4
|
+
|
|
5
|
+
/** Returns { go, position }: go when this pid is first in line and a slot is free. */
|
|
6
|
+
export function decide({ holders, queue }, pid, max) {
|
|
7
|
+
const index = queue.findIndex((ticket) => ticket.pid === pid);
|
|
8
|
+
const position = index < 0 ? queue.length + 1 : index + 1;
|
|
9
|
+
return { go: position === 1 && index === 0 && holders.length < max, position };
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Everything that keeps a new job from starting, as [{ gate, text }]. ahead = waiters in front of the caller. */
|
|
13
|
+
export function gateBlocks({ holders, health, ahead = 0 }, max) {
|
|
14
|
+
const blocks = [];
|
|
15
|
+
if (holders.length >= max) {
|
|
16
|
+
const names = holders.map((h) => `"${h.label}"`).join(" and ");
|
|
17
|
+
blocks.push({ gate: "slots", text: `no free slot: ${holders.length} of ${max} taken, by ${names}` });
|
|
18
|
+
}
|
|
19
|
+
if (health && !health.ok) blocks.push(...health.blocks);
|
|
20
|
+
if (!blocks.length && ahead > 0) blocks.push({ gate: "line", text: `not first in line: ${ahead} ahead` });
|
|
21
|
+
return blocks;
|
|
22
|
+
}
|
|
23
|
+
export const blockText = (blocks) => blocks.map((b) => b.text).join("; ");
|
|
24
|
+
/** The same as one sentence; "" when a job could start now. */
|
|
25
|
+
export const gateReason = (state, max) => blockText(gateBlocks(state, max));
|
|
26
|
+
|
|
27
|
+
/** The blocks a waiter's time is booked to: full slots alone, else the health gate, else the line in front. */
|
|
28
|
+
export function blockReason({ holders, health, ahead = 0 }, max) {
|
|
29
|
+
if (holders.length >= max) return gateBlocks({ holders, health: null }, max);
|
|
30
|
+
if (health && !health.ok) return health.blocks;
|
|
31
|
+
return gateBlocks({ holders, health: null, ahead }, max);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** maxWaitMin of 0 means no limit. */
|
|
35
|
+
export function shouldGiveUp({ startedAt, now, maxWaitMin }) {
|
|
36
|
+
return maxWaitMin > 0 && now - startedAt >= maxWaitMin * MINUTE;
|
|
37
|
+
}
|