@leitwerk-dev/worker-runners 0.1.2 → 0.1.3
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/dist/docker-engine-client.d.ts +86 -0
- package/dist/docker-engine-client.d.ts.map +1 -0
- package/dist/docker-engine-client.js +10 -0
- package/dist/docker-engine-client.js.map +1 -0
- package/dist/docker-engine-http-client.d.ts +10 -11
- package/dist/docker-engine-http-client.d.ts.map +1 -0
- package/dist/docker-engine-http-client.js +201 -14
- package/dist/docker-engine-http-client.js.map +1 -1
- package/dist/docker-worker-runner.d.ts +7 -9
- package/dist/docker-worker-runner.d.ts.map +1 -0
- package/dist/docker-worker-runner.js +235 -9
- package/dist/docker-worker-runner.js.map +1 -1
- package/dist/fake-docker-engine-client.d.ts +40 -0
- package/dist/fake-docker-engine-client.d.ts.map +1 -0
- package/dist/fake-docker-engine-client.js +131 -0
- package/dist/fake-docker-engine-client.js.map +1 -0
- package/dist/index.d.ts +12 -96
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -284
- package/dist/index.js.map +1 -1
- package/dist/kubernetes-api-client.d.ts +71 -0
- package/dist/kubernetes-api-client.d.ts.map +1 -0
- package/dist/kubernetes-api-client.js +142 -0
- package/dist/kubernetes-api-client.js.map +1 -0
- package/dist/kubernetes-http-client.d.ts +5 -8
- package/dist/kubernetes-http-client.d.ts.map +1 -0
- package/dist/kubernetes-http-client.js +287 -298
- package/dist/kubernetes-http-client.js.map +1 -1
- package/dist/kubernetes-manifests.d.ts +232 -0
- package/dist/kubernetes-manifests.d.ts.map +1 -0
- package/dist/kubernetes-manifests.js +370 -0
- package/dist/kubernetes-manifests.js.map +1 -0
- package/dist/kubernetes-worker-runner.d.ts +6 -7
- package/dist/kubernetes-worker-runner.d.ts.map +1 -0
- package/dist/kubernetes-worker-runner.js +161 -9
- package/dist/kubernetes-worker-runner.js.map +1 -1
- package/dist/local-worker-runner.d.ts +7 -9
- package/dist/local-worker-runner.d.ts.map +1 -0
- package/dist/local-worker-runner.js +108 -11
- package/dist/local-worker-runner.js.map +1 -1
- package/dist/process-volume-retention.d.ts +21 -0
- package/dist/process-volume-retention.d.ts.map +1 -0
- package/dist/process-volume-retention.js +46 -0
- package/dist/process-volume-retention.js.map +1 -0
- package/dist/runner-utils.d.ts +16 -0
- package/dist/runner-utils.d.ts.map +1 -0
- package/dist/runner-utils.js +36 -0
- package/dist/runner-utils.js.map +1 -0
- package/dist/types.d.ts +16 -16
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +11 -0
- package/dist/types.js.map +1 -1
- package/dist/worker-labels.d.ts +50 -0
- package/dist/worker-labels.d.ts.map +1 -0
- package/dist/worker-labels.js +83 -0
- package/dist/worker-labels.js.map +1 -0
- package/package.json +3 -3
|
@@ -1,12 +1,109 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from "./
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { UnitExitNotifier } from "./runner-utils.js";
|
|
6
|
+
export const DEFAULT_LOCAL_WORKER_ENTRY_SPECIFIER = "@leitwerk-dev/worker/worker-entry";
|
|
7
|
+
let localUnitCounter = 0;
|
|
8
|
+
function nextUnitId(instanceId, workerId) {
|
|
9
|
+
localUnitCounter += 1;
|
|
10
|
+
return `local_${instanceId}_${workerId}_${localUnitCounter}`;
|
|
11
|
+
}
|
|
12
|
+
function findServerPackageDir() {
|
|
13
|
+
let current = path.dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
while (true) {
|
|
15
|
+
const candidate = path.join(current, "package.json");
|
|
16
|
+
if (existsSync(candidate))
|
|
17
|
+
return current;
|
|
18
|
+
const parent = path.dirname(current);
|
|
19
|
+
if (parent === current)
|
|
20
|
+
return process.cwd();
|
|
21
|
+
current = parent;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function resolveDefaultWorkerEntryPath() {
|
|
25
|
+
return fileURLToPath(import.meta.resolve(DEFAULT_LOCAL_WORKER_ENTRY_SPECIFIER));
|
|
26
|
+
}
|
|
27
|
+
export function resolveLocalWorkerSpawnArgs(args) {
|
|
28
|
+
return args[0] === DEFAULT_LOCAL_WORKER_ENTRY_SPECIFIER
|
|
29
|
+
? [resolveDefaultWorkerEntryPath(), ...args.slice(1)]
|
|
30
|
+
: [...args];
|
|
31
|
+
}
|
|
32
|
+
function exitInfo(code, signal) {
|
|
33
|
+
return { exitCode: code, signal };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Best-effort local development/test {@link WorkerRunner}.
|
|
37
|
+
*
|
|
38
|
+
* This runner implements the shared runner contract needed to start and stop a
|
|
39
|
+
* local worker over the production WebSocket IPC path. It is not an isolation
|
|
40
|
+
* boundary, has no restart adoption, and ignores image/resource profile semantics.
|
|
41
|
+
* Docker and Kubernetes remain the contract-defining production runners.
|
|
42
|
+
*/
|
|
43
|
+
export function createLocalWorkerRunner(options) {
|
|
44
|
+
const command = options.command ?? "node";
|
|
45
|
+
const args = resolveLocalWorkerSpawnArgs(options.args ?? [DEFAULT_LOCAL_WORKER_ENTRY_SPECIFIER]);
|
|
46
|
+
const cwd = options.cwd ?? findServerPackageDir();
|
|
47
|
+
const localWorkerSpawnImpl = options.localWorkerSpawnImpl ?? spawn;
|
|
48
|
+
const units = new Map();
|
|
49
|
+
const exitNotifier = new UnitExitNotifier();
|
|
50
|
+
function wrap(ref) {
|
|
51
|
+
return exitNotifier.wrapUnit(ref, ref.unitId);
|
|
52
|
+
}
|
|
53
|
+
const runner = {
|
|
54
|
+
async start(input) {
|
|
55
|
+
if (input.isolation.dind !== false) {
|
|
56
|
+
throw new Error("Local worker runner does not support Docker-in-Docker profiles");
|
|
57
|
+
}
|
|
58
|
+
const unitId = nextUnitId(input.instanceId, input.workerId);
|
|
59
|
+
const ref = { instanceId: input.instanceId, workerId: input.workerId, unitId };
|
|
60
|
+
const child = localWorkerSpawnImpl(command, args, {
|
|
61
|
+
cwd,
|
|
62
|
+
stdio: ["ignore", "inherit", "inherit"],
|
|
63
|
+
env: { ...process.env, ...input.env },
|
|
64
|
+
});
|
|
65
|
+
const state = {
|
|
66
|
+
ref,
|
|
67
|
+
child,
|
|
68
|
+
status: "running",
|
|
69
|
+
};
|
|
70
|
+
units.set(unitId, state);
|
|
71
|
+
child.once("exit", (code, signal) => {
|
|
72
|
+
state.status = "exited";
|
|
73
|
+
exitNotifier.fireExit(unitId, exitInfo(code, signal));
|
|
74
|
+
});
|
|
75
|
+
child.once("error", (error) => {
|
|
76
|
+
state.status = "exited";
|
|
77
|
+
exitNotifier.fireExit(unitId, {
|
|
78
|
+
exitCode: null,
|
|
79
|
+
signal: null,
|
|
80
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
return wrap(ref);
|
|
84
|
+
},
|
|
85
|
+
async stop(ref, opts) {
|
|
86
|
+
const state = units.get(ref.unitId);
|
|
87
|
+
if (!state || state.status === "exited")
|
|
88
|
+
return;
|
|
89
|
+
state.status = "stopping";
|
|
90
|
+
const child = state.child;
|
|
91
|
+
const exited = new Promise((resolve) => child.once("exit", () => resolve()));
|
|
92
|
+
child.kill("SIGTERM");
|
|
93
|
+
const timedOut = await Promise.race([
|
|
94
|
+
exited.then(() => false),
|
|
95
|
+
new Promise((resolve) => setTimeout(() => resolve(true), opts.graceMs)),
|
|
96
|
+
]);
|
|
97
|
+
if (timedOut)
|
|
98
|
+
child.kill("SIGKILL");
|
|
99
|
+
},
|
|
100
|
+
async list() {
|
|
101
|
+
return [];
|
|
102
|
+
},
|
|
103
|
+
async adopt(descriptor) {
|
|
104
|
+
throw new Error(`Cannot adopt local worker ${descriptor.unitId}: local runner does not support adoption`);
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
return { runner };
|
|
108
|
+
}
|
|
12
109
|
//# sourceMappingURL=local-worker-runner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"file":"local-worker-runner.js","sourceRoot":"","sources":["../src/local-worker-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAWrD,MAAM,CAAC,MAAM,oCAAoC,GAAG,mCAAmC,CAAC;AAmBxF,IAAI,gBAAgB,GAAG,CAAC,CAAC;AAEzB,SAAS,UAAU,CAAC,UAAkB,EAAE,QAAgB;IACvD,gBAAgB,IAAI,CAAC,CAAC;IACtB,OAAO,SAAS,UAAU,IAAI,QAAQ,IAAI,gBAAgB,EAAE,CAAC;AAC9D,CAAC;AAED,SAAS,oBAAoB;IAC5B,IAAI,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3D,OAAO,IAAI,EAAE,CAAC;QACb,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;QACrD,IAAI,UAAU,CAAC,SAAS,CAAC;YAAE,OAAO,OAAO,CAAC;QAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACrC,IAAI,MAAM,KAAK,OAAO;YAAE,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC;QAC7C,OAAO,GAAG,MAAM,CAAC;IAClB,CAAC;AACF,CAAC;AAED,SAAS,6BAA6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|
3
|
+
export interface ProcessVolumeRetentionPolicy {
|
|
4
|
+
completedProcessRetention: string;
|
|
5
|
+
errorProcessRetention: string;
|
|
6
|
+
}
|
|
7
|
+
export interface PlanProcessVolumeRetentionCleanupInput {
|
|
8
|
+
processes: readonly ProcessInstance[];
|
|
9
|
+
now: Date;
|
|
10
|
+
policy: ProcessVolumeRetentionPolicy;
|
|
11
|
+
alreadyReleased?: ReadonlySet<string>;
|
|
12
|
+
}
|
|
13
|
+
export declare function planProcessVolumeRetentionCleanup(input: PlanProcessVolumeRetentionCleanupInput): string[];
|
|
14
|
+
export declare function cleanupRetainedProcessVolumes(input: {
|
|
15
|
+
volume?: ProcessVolume;
|
|
16
|
+
processes: readonly ProcessInstance[];
|
|
17
|
+
now: Date;
|
|
18
|
+
policy: ProcessVolumeRetentionPolicy;
|
|
19
|
+
alreadyReleased?: ReadonlySet<string>;
|
|
20
|
+
}): Promise<string[]>;
|
|
21
|
+
//# sourceMappingURL=process-volume-retention.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-volume-retention.d.ts","sourceRoot":"","sources":["../src/process-volume-retention.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,MAAM,WAAW,4BAA4B;IAC5C,yBAAyB,EAAE,MAAM,CAAC;IAClC,qBAAqB,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,sCAAsC;IACtD,SAAS,EAAE,SAAS,eAAe,EAAE,CAAC;IACtC,GAAG,EAAE,IAAI,CAAC;IACV,MAAM,EAAE,4BAA4B,CAAC;IACrC,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CACtC;AAcD,wBAAgB,iCAAiC,CAChD,KAAK,EAAE,sCAAsC,GAC3C,MAAM,EAAE,CAyBV;AAED,wBAAsB,6BAA6B,CAAC,KAAK,EAAE;IAC1D,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,SAAS,EAAE,SAAS,eAAe,EAAE,CAAC;IACtC,GAAG,EAAE,IAAI,CAAC;IACV,MAAM,EAAE,4BAA4B,CAAC;IACrC,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CACtC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAQpB"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { parseDurationMs } from "@leitwerk-dev/watcher-utils";
|
|
2
|
+
function retentionMs(value) {
|
|
3
|
+
return parseDurationMs(value, Number.POSITIVE_INFINITY, { allowHours: true });
|
|
4
|
+
}
|
|
5
|
+
function closedAtMs(process) {
|
|
6
|
+
if (!process.closedAt) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
const parsed = Date.parse(process.closedAt);
|
|
10
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
11
|
+
}
|
|
12
|
+
export function planProcessVolumeRetentionCleanup(input) {
|
|
13
|
+
const completedRetentionMs = retentionMs(input.policy.completedProcessRetention);
|
|
14
|
+
const errorRetentionMs = retentionMs(input.policy.errorProcessRetention);
|
|
15
|
+
const nowMs = input.now.getTime();
|
|
16
|
+
const alreadyReleased = input.alreadyReleased ?? new Set();
|
|
17
|
+
const candidates = [];
|
|
18
|
+
for (const process of input.processes) {
|
|
19
|
+
if (alreadyReleased.has(process.id)) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const closed = closedAtMs(process);
|
|
23
|
+
if (closed === null) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const retention = process.lifecycleStatus === "completed"
|
|
27
|
+
? completedRetentionMs
|
|
28
|
+
: process.lifecycleStatus === "aborted" || process.lifecycleStatus === "error"
|
|
29
|
+
? errorRetentionMs
|
|
30
|
+
: Number.POSITIVE_INFINITY;
|
|
31
|
+
if (nowMs - closed >= retention) {
|
|
32
|
+
candidates.push(process.id);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return candidates;
|
|
36
|
+
}
|
|
37
|
+
export async function cleanupRetainedProcessVolumes(input) {
|
|
38
|
+
const candidates = planProcessVolumeRetentionCleanup(input);
|
|
39
|
+
if (input.volume) {
|
|
40
|
+
for (const instanceId of candidates) {
|
|
41
|
+
await input.volume.release(instanceId);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return candidates;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=process-volume-retention.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-volume-retention.js","sourceRoot":"","sources":["../src/process-volume-retention.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAe9D,SAAS,WAAW,CAAC,KAAa;IACjC,OAAO,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,iBAAiB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;AAC/E,CAAC;AAED,SAAS,UAAU,CAAC,OAAwB;IAC3C,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC;IACb,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC5C,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,iCAAiC,CAChD,KAA6C;IAE7C,MAAM,oBAAoB,GAAG,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,yBAAyB,CAAC,CAAC;IACjF,MAAM,gBAAgB,GAAG,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC;IACzE,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IAClC,MAAM,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used by every {@link WorkerRunner}.
|
|
4
|
+
*
|
|
5
|
+
* Each runner implementation tracks physical unit exits and maps them to
|
|
6
|
+
* `WorkerUnit.onExit` callbacks. This utility captures the identical map +
|
|
7
|
+
* fire/wrap logic and leaves only the unit-keying to each runner.
|
|
8
|
+
*/
|
|
9
|
+
export declare class UnitExitNotifier {
|
|
10
|
+
private readonly listeners;
|
|
11
|
+
private readonly exited;
|
|
12
|
+
onExit(key: string, listener: (info: WorkerExitInfo) => void): void;
|
|
13
|
+
fireExit(key: string, info: WorkerExitInfo): void;
|
|
14
|
+
wrapUnit<T extends WorkerUnitRef>(ref: T, key: string): WorkerUnit;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=runner-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner-utils.d.ts","sourceRoot":"","sources":["../src/runner-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE5E;;;;;;GAMG;AACH,qBAAa,gBAAgB;IAC5B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA4D;IACtF,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqC;IAE5D,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,IAAI,GAAG,IAAI;IAWnE,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,GAAG,IAAI;IASjD,QAAQ,CAAC,CAAC,SAAS,aAAa,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,UAAU;CAGlE"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared exit-notification machinery used by every {@link WorkerRunner}.
|
|
3
|
+
*
|
|
4
|
+
* Each runner implementation tracks physical unit exits and maps them to
|
|
5
|
+
* `WorkerUnit.onExit` callbacks. This utility captures the identical map +
|
|
6
|
+
* fire/wrap logic and leaves only the unit-keying to each runner.
|
|
7
|
+
*/
|
|
8
|
+
export class UnitExitNotifier {
|
|
9
|
+
listeners = new Map();
|
|
10
|
+
exited = new Map();
|
|
11
|
+
onExit(key, listener) {
|
|
12
|
+
const exit = this.exited.get(key);
|
|
13
|
+
if (exit) {
|
|
14
|
+
queueMicrotask(() => listener(exit));
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const list = this.listeners.get(key) ?? [];
|
|
18
|
+
list.push(listener);
|
|
19
|
+
this.listeners.set(key, list);
|
|
20
|
+
}
|
|
21
|
+
fireExit(key, info) {
|
|
22
|
+
if (this.exited.has(key))
|
|
23
|
+
return;
|
|
24
|
+
this.exited.set(key, info);
|
|
25
|
+
const list = this.listeners.get(key);
|
|
26
|
+
if (!list)
|
|
27
|
+
return;
|
|
28
|
+
this.listeners.delete(key);
|
|
29
|
+
for (const listener of list.splice(0))
|
|
30
|
+
listener(info);
|
|
31
|
+
}
|
|
32
|
+
wrapUnit(ref, key) {
|
|
33
|
+
return { ...ref, onExit: (listener) => this.onExit(key, listener) };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=runner-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner-utils.js","sourceRoot":"","sources":["../src/runner-utils.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,OAAO,gBAAgB;IACX,SAAS,GAAG,IAAI,GAAG,EAAiD,CAAC;IACrE,MAAM,GAAG,IAAI,GAAG,EAA0B,CAAC;IAE5D,MAAM,CAAC,GAAW,EAAE,QAAwC;QAC3D,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAClC,IAAI,IAAI,EAAE,CAAC;YACV,cAAc,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;YACrC,OAAO;QACR,CAAC;QACD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QAC3C,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACpB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED,QAAQ,CAAC,GAAW,EAAE,IAAoB;QACzC,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,OAAO;QACjC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAC3B,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACrC,IAAI,CAAC,IAAI;YAAE,OAAO;QAClB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC3B,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;YAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;IACvD,CAAC;IAED,QAAQ,CAA0B,GAAM,EAAE,GAAW;QACpD,OAAO,EAAE,GAAG,GAAG,EAAE,MAAM,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,EAAE,CAAC;IACrE,CAAC;CACD"}
|
package/dist/types.d.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* state over the protocol (the session-snapshot exchange), never by reading the
|
|
16
16
|
* volume, which keeps every run mode symmetric.
|
|
17
17
|
*/
|
|
18
|
-
interface VolumeRef {
|
|
18
|
+
export interface VolumeRef {
|
|
19
19
|
instanceId: string;
|
|
20
20
|
/** Runtime-specific identifier (host path, named volume, PVC name). */
|
|
21
21
|
id: string;
|
|
@@ -24,7 +24,7 @@ interface VolumeRef {
|
|
|
24
24
|
/** Runtime-specific namespace/project for the volume (Kubernetes process namespace). */
|
|
25
25
|
namespace?: string;
|
|
26
26
|
}
|
|
27
|
-
interface ProcessVolume {
|
|
27
|
+
export interface ProcessVolume {
|
|
28
28
|
/** Idempotently provisions durable storage for a process instance. */
|
|
29
29
|
ensure(instanceId: string): Promise<VolumeRef>;
|
|
30
30
|
/** Retention cleanup only. Stopping a worker never calls this. */
|
|
@@ -36,11 +36,11 @@ interface ProcessVolume {
|
|
|
36
36
|
* Output of runtime-profile selection. MVP resolves to a single configured
|
|
37
37
|
* worker image; repository branch content must never select an image.
|
|
38
38
|
*/
|
|
39
|
-
interface ResolvedWorkerImage {
|
|
39
|
+
export interface ResolvedWorkerImage {
|
|
40
40
|
/** Fully qualified image reference, ideally digest-pinned. */
|
|
41
41
|
reference: string;
|
|
42
42
|
}
|
|
43
|
-
interface WorkerResourceLimits {
|
|
43
|
+
export interface WorkerResourceLimits {
|
|
44
44
|
cpu?: string;
|
|
45
45
|
memory?: string;
|
|
46
46
|
}
|
|
@@ -52,12 +52,12 @@ interface WorkerResourceLimits {
|
|
|
52
52
|
* - `{ dind: "sysbox" }` — nested daemon without `--privileged` (host must
|
|
53
53
|
* provide the sysbox runtime).
|
|
54
54
|
*/
|
|
55
|
-
type WorkerIsolation = {
|
|
55
|
+
export type WorkerIsolation = {
|
|
56
56
|
dind: false;
|
|
57
57
|
} | {
|
|
58
58
|
dind: "privileged" | "sysbox";
|
|
59
59
|
};
|
|
60
|
-
interface WorkerUnitRef {
|
|
60
|
+
export interface WorkerUnitRef {
|
|
61
61
|
instanceId: string;
|
|
62
62
|
workerId: string;
|
|
63
63
|
/** Runtime-specific handle id (container id, pod name). */
|
|
@@ -65,7 +65,7 @@ interface WorkerUnitRef {
|
|
|
65
65
|
/** Runtime-specific namespace/project for the unit (Kubernetes process namespace). */
|
|
66
66
|
namespace?: string;
|
|
67
67
|
}
|
|
68
|
-
interface WorkerExitInfo {
|
|
68
|
+
export interface WorkerExitInfo {
|
|
69
69
|
/** Process exit code when the runtime reports one. */
|
|
70
70
|
exitCode: number | null;
|
|
71
71
|
/** Termination signal when the runtime reports one. */
|
|
@@ -75,11 +75,11 @@ interface WorkerExitInfo {
|
|
|
75
75
|
/** Human-readable reason surfaced by the runtime, if any. */
|
|
76
76
|
reason?: string;
|
|
77
77
|
}
|
|
78
|
-
interface WorkerUnit extends WorkerUnitRef {
|
|
78
|
+
export interface WorkerUnit extends WorkerUnitRef {
|
|
79
79
|
/** Maps physical worker exit into the supervisor's existing failure paths. */
|
|
80
80
|
onExit(listener: (info: WorkerExitInfo) => void): void;
|
|
81
81
|
}
|
|
82
|
-
interface WorkerUnitDescriptor extends WorkerUnitRef {
|
|
82
|
+
export interface WorkerUnitDescriptor extends WorkerUnitRef {
|
|
83
83
|
observedState?: "running" | "pending" | "terminal" | "unknown";
|
|
84
84
|
}
|
|
85
85
|
interface StartWorkerInputBase {
|
|
@@ -94,21 +94,21 @@ interface StartWorkerInputBase {
|
|
|
94
94
|
resources?: WorkerResourceLimits;
|
|
95
95
|
}
|
|
96
96
|
/** Start input for the best-effort local runner, which uses configured host storage. */
|
|
97
|
-
interface LocalStartWorkerInput extends StartWorkerInputBase {
|
|
97
|
+
export interface LocalStartWorkerInput extends StartWorkerInputBase {
|
|
98
98
|
runnerKind: "local";
|
|
99
99
|
volume?: never;
|
|
100
100
|
}
|
|
101
101
|
/** Start input for isolated runners, whose durable process volume is mandatory. */
|
|
102
|
-
interface IsolatedStartWorkerInput extends StartWorkerInputBase {
|
|
102
|
+
export interface IsolatedStartWorkerInput extends StartWorkerInputBase {
|
|
103
103
|
runnerKind: "isolated";
|
|
104
104
|
volume: VolumeRef;
|
|
105
105
|
}
|
|
106
|
-
type StartWorkerInput = LocalStartWorkerInput | IsolatedStartWorkerInput;
|
|
107
|
-
interface StopWorkerOptions {
|
|
106
|
+
export type StartWorkerInput = LocalStartWorkerInput | IsolatedStartWorkerInput;
|
|
107
|
+
export interface StopWorkerOptions {
|
|
108
108
|
/** Grace period before forceful termination. The volume is always kept. */
|
|
109
109
|
graceMs: number;
|
|
110
110
|
}
|
|
111
|
-
interface WorkerRunner<TStartInput extends StartWorkerInput = StartWorkerInput> {
|
|
111
|
+
export interface WorkerRunner<TStartInput extends StartWorkerInput = StartWorkerInput> {
|
|
112
112
|
start(input: TStartInput): Promise<WorkerUnit>;
|
|
113
113
|
/** Stops the unit but keeps the process volume for resume. */
|
|
114
114
|
stop(ref: WorkerUnitRef, opts: StopWorkerOptions): Promise<void>;
|
|
@@ -117,5 +117,5 @@ interface WorkerRunner<TStartInput extends StartWorkerInput = StartWorkerInput>
|
|
|
117
117
|
/** Reconnects to a live unit discovered by {@link WorkerRunner.list}. */
|
|
118
118
|
adopt(descriptor: WorkerUnitDescriptor): Promise<WorkerUnit>;
|
|
119
119
|
}
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
export {};
|
|
121
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;;;GAMG;AACH,MAAM,WAAW,SAAS;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,uEAAuE;IACvE,EAAE,EAAE,MAAM,CAAC;IACX,oEAAoE;IACpE,SAAS,EAAE,MAAM,CAAC;IAClB,wFAAwF;IACxF,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,aAAa;IAC7B,sEAAsE;IACtE,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAC/C,kEAAkE;IAClE,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,oFAAoF;IACpF,sBAAsB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1D;AAED;;;GAGG;AACH,MA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AAM,CAAC,CAAC;IAC5B,SAAS,EAAE,eAAe,CAAC;IAC3B,SAAS,CAAC,EAAE,oBAAoB,CAAC;CACjC;AAED,wFAAwF;AACxF,MAAM,WAAW,qBAAsB,SAAQ,oBAAoB;IAClE,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,KAAK,CAAC;CACf;AAED,mFAAmF;AACnF,MAAM,WAAW,wBAAyB,SAAQ,oBAAoB;IACrE,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,EAAE,SAAS,CAAC;CAClB;AAED,MAAM,MAAM,gBAAgB,GAAG,qBAAqB,GAAG,wBAAwB,CAAC;AAEhF,MAAM,WAAW,iBAAiB;IACjC,2EAA2E;IAC3E,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,YAAY,CAAC,WAAW,SAAS,gBAAgB,GAAG,gBAAgB;IACpF,KAAK,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAC/C,8DAA8D;IAC9D,IAAI,CAAC,GAAG,EAAE,aAAa,EAAE,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjE,kDAAkD;IAClD,IAAI,IAAI,OAAO,CAAC,oBAAoB,EAAE,CAAC,CAAC;IACxC,yEAAyE;IACzE,KAAK,CAAC,UAAU,EAAE,oBAAoB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CAC7D"}
|
package/dist/types.js
CHANGED
|
@@ -1 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runner API seams shared by worker run modes (Docker, Kubernetes, best-effort local).
|
|
3
|
+
*
|
|
4
|
+
* The seam is cut so the runtimes share everything except the runtime-specific
|
|
5
|
+
* bodies of two interfaces. The IPC transport is deliberately *not* a runner
|
|
6
|
+
* axis: the runner only injects connect env, the worker dials back over
|
|
7
|
+
* WebSocket, and the existing `WorkerWebSocketIpcManager` binds the socket to
|
|
8
|
+
* the lease. The supervisor stays the lease/lifecycle coordinator; the runner
|
|
9
|
+
* only does runtime-specific work.
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
|
1
12
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared labelling for worker units across runner modes.
|
|
3
|
+
*
|
|
4
|
+
* Labels are how the server reconciles which workers exist after a restart:
|
|
5
|
+
* there is no pid registry, the container/pod runtime is the source of truth.
|
|
6
|
+
* Both the Docker and Kubernetes runners stamp these labels at start and read
|
|
7
|
+
* them back during the adoption scan, so the keys and parse rules live here
|
|
8
|
+
* rather than in a runtime-specific body.
|
|
9
|
+
*/
|
|
10
|
+
export declare const WORKER_LABEL_MANAGED_BY = "leitwerk.dev/managed-by";
|
|
11
|
+
export declare const WORKER_LABEL_COMPONENT = "leitwerk.dev/component";
|
|
12
|
+
export declare const WORKER_LABEL_INSTANCE_ID = "leitwerk.dev/instance-id";
|
|
13
|
+
export declare const WORKER_LABEL_WORKER_ID = "leitwerk.dev/worker-id";
|
|
14
|
+
export declare const WORKER_LABEL_SERVER_EPOCH = "leitwerk.dev/server-epoch";
|
|
15
|
+
export declare const WORKER_LABEL_MANAGED_BY_VALUE = "leitwerk";
|
|
16
|
+
export declare const WORKER_LABEL_COMPONENT_VALUE = "worker";
|
|
17
|
+
export declare const PROCESS_NAMESPACE_COMPONENT_VALUE = "process-namespace";
|
|
18
|
+
export declare const PROCESS_VOLUME_COMPONENT_VALUE = "process-volume";
|
|
19
|
+
export declare const PROCESS_SERVER_CA_COMPONENT_VALUE = "server-ca";
|
|
20
|
+
export declare const PROCESS_IMAGE_PULL_SECRET_COMPONENT_VALUE = "image-pull-secret";
|
|
21
|
+
export interface WorkerUnitIdentity {
|
|
22
|
+
instanceId: string;
|
|
23
|
+
workerId: string;
|
|
24
|
+
serverEpoch: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Builds the canonical label set for a worker unit. Extra labels are merged in
|
|
28
|
+
* but can never override the managed identity keys.
|
|
29
|
+
*/
|
|
30
|
+
export declare function buildWorkerUnitLabels(identity: WorkerUnitIdentity, extra?: Record<string, string>): Record<string, string>;
|
|
31
|
+
/**
|
|
32
|
+
* Builds labels for durable process-scoped resources (namespace/PVC). These
|
|
33
|
+
* intentionally omit worker-id and server-epoch because the resources outlive a
|
|
34
|
+
* specific worker lease and are not adoption targets.
|
|
35
|
+
*/
|
|
36
|
+
export declare function buildProcessResourceLabels(args: {
|
|
37
|
+
instanceId: string;
|
|
38
|
+
component: typeof PROCESS_NAMESPACE_COMPONENT_VALUE | typeof PROCESS_VOLUME_COMPONENT_VALUE | typeof PROCESS_SERVER_CA_COMPONENT_VALUE | typeof PROCESS_IMAGE_PULL_SECRET_COMPONENT_VALUE;
|
|
39
|
+
}, extra?: Record<string, string>): Record<string, string>;
|
|
40
|
+
export declare function managedProcessNamespaceLabelSelector(): Record<string, string>;
|
|
41
|
+
/** True when the labels identify an leitwerk-managed worker unit. */
|
|
42
|
+
export declare function isManagedWorkerUnitLabels(labels: Record<string, string>): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Recovers the worker identity from a unit's labels, or `null` when the labels
|
|
45
|
+
* do not describe a complete leitwerk-managed worker.
|
|
46
|
+
*/
|
|
47
|
+
export declare function parseWorkerUnitIdentity(labels: Record<string, string>): WorkerUnitIdentity | null;
|
|
48
|
+
/** Label selector for listing managed worker units in a runtime query. */
|
|
49
|
+
export declare function managedWorkerLabelSelector(): Record<string, string>;
|
|
50
|
+
//# sourceMappingURL=worker-labels.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-labels.d.ts","sourceRoot":"","sources":["../src/worker-labels.ts"],"names":[],"mappings":"A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ED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,kBAAkB,GAAG,IAAI,CAWjG;AAED,0EAA0E;AAC1E,wBAAgB,0BAA0B,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAEnE"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared labelling for worker units across runner modes.
|
|
3
|
+
*
|
|
4
|
+
* Labels are how the server reconciles which workers exist after a restart:
|
|
5
|
+
* there is no pid registry, the container/pod runtime is the source of truth.
|
|
6
|
+
* Both the Docker and Kubernetes runners stamp these labels at start and read
|
|
7
|
+
* them back during the adoption scan, so the keys and parse rules live here
|
|
8
|
+
* rather than in a runtime-specific body.
|
|
9
|
+
*/
|
|
10
|
+
export const WORKER_LABEL_MANAGED_BY = "leitwerk.dev/managed-by";
|
|
11
|
+
export const WORKER_LABEL_COMPONENT = "leitwerk.dev/component";
|
|
12
|
+
export const WORKER_LABEL_INSTANCE_ID = "leitwerk.dev/instance-id";
|
|
13
|
+
export const WORKER_LABEL_WORKER_ID = "leitwerk.dev/worker-id";
|
|
14
|
+
export const WORKER_LABEL_SERVER_EPOCH = "leitwerk.dev/server-epoch";
|
|
15
|
+
export const WORKER_LABEL_MANAGED_BY_VALUE = "leitwerk";
|
|
16
|
+
export const WORKER_LABEL_COMPONENT_VALUE = "worker";
|
|
17
|
+
export const PROCESS_NAMESPACE_COMPONENT_VALUE = "process-namespace";
|
|
18
|
+
export const PROCESS_VOLUME_COMPONENT_VALUE = "process-volume";
|
|
19
|
+
export const PROCESS_SERVER_CA_COMPONENT_VALUE = "server-ca";
|
|
20
|
+
export const PROCESS_IMAGE_PULL_SECRET_COMPONENT_VALUE = "image-pull-secret";
|
|
21
|
+
/**
|
|
22
|
+
* Builds the canonical label set for a worker unit. Extra labels are merged in
|
|
23
|
+
* but can never override the managed identity keys.
|
|
24
|
+
*/
|
|
25
|
+
export function buildWorkerUnitLabels(identity, extra = {}) {
|
|
26
|
+
return {
|
|
27
|
+
...extra,
|
|
28
|
+
[WORKER_LABEL_MANAGED_BY]: WORKER_LABEL_MANAGED_BY_VALUE,
|
|
29
|
+
[WORKER_LABEL_COMPONENT]: WORKER_LABEL_COMPONENT_VALUE,
|
|
30
|
+
[WORKER_LABEL_INSTANCE_ID]: identity.instanceId,
|
|
31
|
+
[WORKER_LABEL_WORKER_ID]: identity.workerId,
|
|
32
|
+
[WORKER_LABEL_SERVER_EPOCH]: identity.serverEpoch,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Builds labels for durable process-scoped resources (namespace/PVC). These
|
|
37
|
+
* intentionally omit worker-id and server-epoch because the resources outlive a
|
|
38
|
+
* specific worker lease and are not adoption targets.
|
|
39
|
+
*/
|
|
40
|
+
export function buildProcessResourceLabels(args, extra = {}) {
|
|
41
|
+
return {
|
|
42
|
+
...extra,
|
|
43
|
+
[WORKER_LABEL_MANAGED_BY]: WORKER_LABEL_MANAGED_BY_VALUE,
|
|
44
|
+
[WORKER_LABEL_COMPONENT]: args.component,
|
|
45
|
+
[WORKER_LABEL_INSTANCE_ID]: args.instanceId,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** Selector for the two managed-by/component keys shared by every managed resource. */
|
|
49
|
+
function managedResourceLabelSelector(component) {
|
|
50
|
+
return {
|
|
51
|
+
[WORKER_LABEL_MANAGED_BY]: WORKER_LABEL_MANAGED_BY_VALUE,
|
|
52
|
+
[WORKER_LABEL_COMPONENT]: component,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export function managedProcessNamespaceLabelSelector() {
|
|
56
|
+
return managedResourceLabelSelector(PROCESS_NAMESPACE_COMPONENT_VALUE);
|
|
57
|
+
}
|
|
58
|
+
/** True when the labels identify an leitwerk-managed worker unit. */
|
|
59
|
+
export function isManagedWorkerUnitLabels(labels) {
|
|
60
|
+
return (labels[WORKER_LABEL_MANAGED_BY] === WORKER_LABEL_MANAGED_BY_VALUE &&
|
|
61
|
+
labels[WORKER_LABEL_COMPONENT] === WORKER_LABEL_COMPONENT_VALUE);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Recovers the worker identity from a unit's labels, or `null` when the labels
|
|
65
|
+
* do not describe a complete leitwerk-managed worker.
|
|
66
|
+
*/
|
|
67
|
+
export function parseWorkerUnitIdentity(labels) {
|
|
68
|
+
if (!isManagedWorkerUnitLabels(labels)) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
const instanceId = labels[WORKER_LABEL_INSTANCE_ID];
|
|
72
|
+
const workerId = labels[WORKER_LABEL_WORKER_ID];
|
|
73
|
+
const serverEpoch = labels[WORKER_LABEL_SERVER_EPOCH];
|
|
74
|
+
if (!instanceId || !workerId || !serverEpoch) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
return { instanceId, workerId, serverEpoch };
|
|
78
|
+
}
|
|
79
|
+
/** Label selector for listing managed worker units in a runtime query. */
|
|
80
|
+
export function managedWorkerLabelSelector() {
|
|
81
|
+
return managedResourceLabelSelector(WORKER_LABEL_COMPONENT_VALUE);
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=worker-labels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-labels.js","sourceRoot":"","sources":["../src/worker-labels.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,CAAC,MAAM,uBAAuB,GAAG,yBAAyB,CAAC;AACjE,MAAM,CAAC,MAAM,sBAAsB,GAAG,wBAAwB,CAAC;AAC/D,MAAM,CAAC,MAAM,wBAAwB,GAAG,0BAA0B,CAAC;AACnE,MAAM,CAAC,MAAM,sBAAsB,GAAG,wBAAwB,CAAC;AAC/D,MAAM,CAAC,MAAM,yBAAyB,GAAG,2BAA2B,CAAC;AAErE,MAAM,CAAC,MAAM,6BAA6B,GAAG,UAAU,CAAC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AC,KAAK,6BAA6B;QACjE,MAAM,CAAC,sBAAsB,CAAC,KAAK,4BAA4B,CAC/D,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CAAC,MAA8B;IACrE,IAAI,CAAC,yBAAyB,CAAC,MAAM,CAAC,EAAE,CAAC;QACxC,OAAO,IAAI,CAAC;IACb,CAAC;IACD,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAAC,CAAC;IACpD,MAAM,QAAQ,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC;IAChD,MAAM,WAAW,GAAG,MAAM,CAAC,yBAAyB,CAAC,CAAC;IACtD,IAAI,CAAC,UAAU,IAAI,CAAC,QAAQ,IAAI,CAAC,WAAW,EAAE,CAAC;QAC9C,OAAO,IAAI,CAAC;IACb,CAAC;IACD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;AAC9C,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,0BAA0B;IACzC,OAAO,4BAA4B,CAAC,4BAA4B,CAAC,CAAC;AACnE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leitwerk-dev/worker-runners",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/leitwerk-dev/leitwerk.git",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"build": "tsup --silent"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@leitwerk-dev/domain": "0.1.
|
|
52
|
-
"@leitwerk-dev/watcher-utils": "0.1.
|
|
51
|
+
"@leitwerk-dev/domain": "0.1.3",
|
|
52
|
+
"@leitwerk-dev/watcher-utils": "0.1.3"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/node": "^22.15.30",
|