@rallycry/conveyor-agent 11.0.2 → 11.0.4

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.
@@ -0,0 +1,76 @@
1
+ // src/runner/heavy-gate.ts
2
+ import { readdirSync, readFileSync, statSync } from "fs";
3
+ import path from "path";
4
+ var GATE_KEYS = ["heavy", "test", "typecheck", "build"];
5
+ var GATES_DIR_NAME = "gates";
6
+ function runDir() {
7
+ return process.env.CONVEYOR_RUN_DIR ?? "/tmp/conveyor-run";
8
+ }
9
+ function gatesDir() {
10
+ return path.join(runDir(), GATES_DIR_NAME);
11
+ }
12
+ function pidAlive(pid) {
13
+ try {
14
+ process.kill(pid, 0);
15
+ return true;
16
+ } catch {
17
+ return false;
18
+ }
19
+ }
20
+ function parsePid(raw) {
21
+ const pid = Number.parseInt(raw.trim(), 10);
22
+ return Number.isInteger(pid) && pid > 0 ? pid : null;
23
+ }
24
+ function gatePidFiles() {
25
+ const files = GATE_KEYS.map((key) => path.join(runDir(), `${key}.pid`));
26
+ try {
27
+ for (const entry of readdirSync(gatesDir())) {
28
+ if (entry.endsWith(".pid")) files.push(path.join(gatesDir(), entry));
29
+ }
30
+ } catch {
31
+ }
32
+ return files;
33
+ }
34
+ function listGateExitSentinels() {
35
+ const sentinels = [];
36
+ let entries;
37
+ try {
38
+ entries = readdirSync(gatesDir());
39
+ } catch {
40
+ return sentinels;
41
+ }
42
+ for (const entry of entries) {
43
+ if (!entry.endsWith(".exit")) continue;
44
+ const file = path.join(gatesDir(), entry);
45
+ try {
46
+ const mtimeMs = statSync(file).mtimeMs;
47
+ let code = null;
48
+ try {
49
+ const parsed = JSON.parse(readFileSync(file, "utf8"));
50
+ const value = parsed?.code;
51
+ if (typeof value === "number") code = value;
52
+ } catch {
53
+ }
54
+ sentinels.push({ path: file, label: entry.slice(0, -".exit".length), code, mtimeMs });
55
+ } catch {
56
+ }
57
+ }
58
+ sentinels.sort((a, b) => a.mtimeMs - b.mtimeMs);
59
+ return sentinels;
60
+ }
61
+ function isHeavyGateActive() {
62
+ for (const file of gatePidFiles()) {
63
+ try {
64
+ const pid = parsePid(readFileSync(file, "utf8"));
65
+ if (pid !== null && pidAlive(pid)) return true;
66
+ } catch {
67
+ }
68
+ }
69
+ return false;
70
+ }
71
+
72
+ export {
73
+ gatesDir,
74
+ listGateExitSentinels,
75
+ isHeavyGateActive
76
+ };