@mclawnet/scheduler 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/dist/__tests__/executor-oneshot.test.d.ts +2 -0
- package/dist/__tests__/executor-oneshot.test.d.ts.map +1 -0
- package/dist/__tests__/executor-oneshot.test.js +141 -0
- package/dist/__tests__/executor-oneshot.test.js.map +1 -0
- package/dist/__tests__/executor-swarm.test.d.ts +2 -0
- package/dist/__tests__/executor-swarm.test.d.ts.map +1 -0
- package/dist/__tests__/executor-swarm.test.js +142 -0
- package/dist/__tests__/executor-swarm.test.js.map +1 -0
- package/dist/__tests__/json-schedule-repository-prompt-cap.test.d.ts +2 -0
- package/dist/__tests__/json-schedule-repository-prompt-cap.test.d.ts.map +1 -0
- package/dist/__tests__/json-schedule-repository-prompt-cap.test.js +64 -0
- package/dist/__tests__/json-schedule-repository-prompt-cap.test.js.map +1 -0
- package/dist/__tests__/json-schedule-repository.test.d.ts +2 -0
- package/dist/__tests__/json-schedule-repository.test.d.ts.map +1 -0
- package/dist/__tests__/json-schedule-repository.test.js +178 -0
- package/dist/__tests__/json-schedule-repository.test.js.map +1 -0
- package/dist/__tests__/paths.test.d.ts +2 -0
- package/dist/__tests__/paths.test.d.ts.map +1 -0
- package/dist/__tests__/paths.test.js +19 -0
- package/dist/__tests__/paths.test.js.map +1 -0
- package/dist/__tests__/scheduler-maxrun-cap.test.d.ts +2 -0
- package/dist/__tests__/scheduler-maxrun-cap.test.d.ts.map +1 -0
- package/dist/__tests__/scheduler-maxrun-cap.test.js +109 -0
- package/dist/__tests__/scheduler-maxrun-cap.test.js.map +1 -0
- package/dist/__tests__/scheduler-service-events-typed.test.d.ts +2 -0
- package/dist/__tests__/scheduler-service-events-typed.test.d.ts.map +1 -0
- package/dist/__tests__/scheduler-service-events-typed.test.js +27 -0
- package/dist/__tests__/scheduler-service-events-typed.test.js.map +1 -0
- package/dist/__tests__/scheduler-service-register.test.d.ts +2 -0
- package/dist/__tests__/scheduler-service-register.test.d.ts.map +1 -0
- package/dist/__tests__/scheduler-service-register.test.js +54 -0
- package/dist/__tests__/scheduler-service-register.test.js.map +1 -0
- package/dist/__tests__/scheduler-service-tick-23.test.d.ts +2 -0
- package/dist/__tests__/scheduler-service-tick-23.test.d.ts.map +1 -0
- package/dist/__tests__/scheduler-service-tick-23.test.js +72 -0
- package/dist/__tests__/scheduler-service-tick-23.test.js.map +1 -0
- package/dist/__tests__/scheduler-service-tick-24.test.d.ts +2 -0
- package/dist/__tests__/scheduler-service-tick-24.test.d.ts.map +1 -0
- package/dist/__tests__/scheduler-service-tick-24.test.js +80 -0
- package/dist/__tests__/scheduler-service-tick-24.test.js.map +1 -0
- package/dist/__tests__/scheduler-service-tick-25.test.d.ts +2 -0
- package/dist/__tests__/scheduler-service-tick-25.test.d.ts.map +1 -0
- package/dist/__tests__/scheduler-service-tick-25.test.js +111 -0
- package/dist/__tests__/scheduler-service-tick-25.test.js.map +1 -0
- package/dist/__tests__/scheduler-service-tick-26.test.d.ts +2 -0
- package/dist/__tests__/scheduler-service-tick-26.test.d.ts.map +1 -0
- package/dist/__tests__/scheduler-service-tick-26.test.js +97 -0
- package/dist/__tests__/scheduler-service-tick-26.test.js.map +1 -0
- package/dist/__tests__/scheduler-service-tick-27.test.d.ts +2 -0
- package/dist/__tests__/scheduler-service-tick-27.test.d.ts.map +1 -0
- package/dist/__tests__/scheduler-service-tick-27.test.js +69 -0
- package/dist/__tests__/scheduler-service-tick-27.test.js.map +1 -0
- package/dist/__tests__/scheduler-service-tick-coalesce.test.d.ts +2 -0
- package/dist/__tests__/scheduler-service-tick-coalesce.test.d.ts.map +1 -0
- package/dist/__tests__/scheduler-service-tick-coalesce.test.js +119 -0
- package/dist/__tests__/scheduler-service-tick-coalesce.test.js.map +1 -0
- package/dist/__tests__/scheduler-service-trigger-gating.test.d.ts +2 -0
- package/dist/__tests__/scheduler-service-trigger-gating.test.d.ts.map +1 -0
- package/dist/__tests__/scheduler-service-trigger-gating.test.js +55 -0
- package/dist/__tests__/scheduler-service-trigger-gating.test.js.map +1 -0
- package/dist/__tests__/tick-helpers.d.ts +17 -0
- package/dist/__tests__/tick-helpers.d.ts.map +1 -0
- package/dist/__tests__/tick-helpers.js +97 -0
- package/dist/__tests__/tick-helpers.js.map +1 -0
- package/dist/executor.d.ts +20 -0
- package/dist/executor.d.ts.map +1 -0
- package/dist/executor.js +2 -0
- package/dist/executor.js.map +1 -0
- package/dist/executors/oneshot.d.ts +22 -0
- package/dist/executors/oneshot.d.ts.map +1 -0
- package/dist/executors/oneshot.js +55 -0
- package/dist/executors/oneshot.js.map +1 -0
- package/dist/executors/swarm.d.ts +26 -0
- package/dist/executors/swarm.d.ts.map +1 -0
- package/dist/executors/swarm.js +40 -0
- package/dist/executors/swarm.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/json-schedule-repository.d.ts +39 -0
- package/dist/json-schedule-repository.d.ts.map +1 -0
- package/dist/json-schedule-repository.js +374 -0
- package/dist/json-schedule-repository.js.map +1 -0
- package/dist/paths.d.ts +7 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +22 -0
- package/dist/paths.js.map +1 -0
- package/dist/scheduler-service.d.ts +71 -0
- package/dist/scheduler-service.d.ts.map +1 -0
- package/dist/scheduler-service.js +395 -0
- package/dist/scheduler-service.js.map +1 -0
- package/dist/types.d.ts +92 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +36 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type Schedule, type ScheduleRun } from "./types.js";
|
|
2
|
+
import type { JsonScheduleRepository } from "./json-schedule-repository.js";
|
|
3
|
+
import type { ScheduleExecutor } from "./executor.js";
|
|
4
|
+
/**
|
|
5
|
+
* Typed event map for {@link SchedulerService.events}. Keeps the runtime
|
|
6
|
+
* EventEmitter at the implementation site but pins the listener shapes so
|
|
7
|
+
* callers don't have to cast.
|
|
8
|
+
*/
|
|
9
|
+
export interface SchedulerEvents {
|
|
10
|
+
change: (s: Schedule) => void;
|
|
11
|
+
run: (r: ScheduleRun) => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Tiny structural type-only declaration that narrows the EventEmitter API to
|
|
15
|
+
* a known event map. We intentionally do NOT subclass EventEmitter — node's
|
|
16
|
+
* generic `EventEmitter<T>` was only added in v20 and we need to stay
|
|
17
|
+
* compatible with older targets, plus this has zero runtime cost.
|
|
18
|
+
*/
|
|
19
|
+
export interface TypedEventEmitter<T> {
|
|
20
|
+
on<K extends keyof T & string>(event: K, listener: T[K] extends (...args: infer A) => void ? (...args: A) => void : never): this;
|
|
21
|
+
off<K extends keyof T & string>(event: K, listener: T[K] extends (...args: infer A) => void ? (...args: A) => void : never): this;
|
|
22
|
+
once<K extends keyof T & string>(event: K, listener: T[K] extends (...args: infer A) => void ? (...args: A) => void : never): this;
|
|
23
|
+
emit<K extends keyof T & string>(event: K, ...args: T[K] extends (...args: infer A) => void ? A : never): boolean;
|
|
24
|
+
removeAllListeners<K extends keyof T & string>(event?: K): this;
|
|
25
|
+
}
|
|
26
|
+
export declare class SchedulerService {
|
|
27
|
+
private readonly repo;
|
|
28
|
+
private readonly executors;
|
|
29
|
+
private readonly cronJobs;
|
|
30
|
+
private readonly activeRuns;
|
|
31
|
+
private readonly activeAbort;
|
|
32
|
+
private readonly cwdLock;
|
|
33
|
+
private readonly pendingRetries;
|
|
34
|
+
private stopped;
|
|
35
|
+
readonly events: TypedEventEmitter<SchedulerEvents>;
|
|
36
|
+
constructor(repo: JsonScheduleRepository, executors: Record<"swarm" | "oneshot", ScheduleExecutor>);
|
|
37
|
+
start(): Promise<void>;
|
|
38
|
+
stop(): Promise<void>;
|
|
39
|
+
register(s: Schedule): void;
|
|
40
|
+
unregister(id: string): void;
|
|
41
|
+
getRegistered(): string[];
|
|
42
|
+
triggerNow(id: string): Promise<ScheduleRun>;
|
|
43
|
+
cancel(runId: string): boolean;
|
|
44
|
+
private tick;
|
|
45
|
+
private runOnce;
|
|
46
|
+
private cwdRetry;
|
|
47
|
+
private makeRunRecord;
|
|
48
|
+
private recordCancelled;
|
|
49
|
+
private finalizeRun;
|
|
50
|
+
private releaseLocks;
|
|
51
|
+
/**
|
|
52
|
+
* Build the combined per-tick patch reflecting the run's outcome:
|
|
53
|
+
* - cancellations: timestamps only (no counter change).
|
|
54
|
+
* - completed: reset counter to 0 (only if it was non-zero).
|
|
55
|
+
* - failed/failed_interrupted: increment counter; if it hits the cap,
|
|
56
|
+
* also flip status → "paused" and skip nextRunAt.
|
|
57
|
+
*/
|
|
58
|
+
private computeFinalizationPatch;
|
|
59
|
+
/**
|
|
60
|
+
* Used by pre-runOnce cancel paths (single-flight, cwd_busy) where there is
|
|
61
|
+
* no executor outcome to feed into counter logic.
|
|
62
|
+
*/
|
|
63
|
+
private computeTimestampsPatch;
|
|
64
|
+
/**
|
|
65
|
+
* Apply the combined patch with one repo.update + one 'change' emit, and
|
|
66
|
+
* unregister the cron job in between if the schedule was just paused so the
|
|
67
|
+
* emitted snapshot reflects the post-pause state.
|
|
68
|
+
*/
|
|
69
|
+
private commitTickPatch;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=scheduler-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduler-service.d.ts","sourceRoot":"","sources":["../src/scheduler-service.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,WAAW,EAIjB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,KAAK,EAAmC,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAQvF;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,CAAC,CAAC,EAAE,QAAQ,KAAK,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X_RUN_MS, } from "./types.js";
|
|
5
|
+
const CWD_RETRY_MS = 60_000;
|
|
6
|
+
export class SchedulerService {
|
|
7
|
+
repo;
|
|
8
|
+
executors;
|
|
9
|
+
cronJobs = new Map();
|
|
10
|
+
activeRuns = new Map(); // scheduleId → run
|
|
11
|
+
activeAbort = new Map(); // runId → controller
|
|
12
|
+
cwdLock = new Map(); // workDir → scheduleId
|
|
13
|
+
pendingRetries = new Map(); // scheduleId → timer
|
|
14
|
+
stopped = false;
|
|
15
|
+
events = new EventEmitter();
|
|
16
|
+
constructor(repo, executors) {
|
|
17
|
+
this.repo = repo;
|
|
18
|
+
this.executors = executors;
|
|
19
|
+
}
|
|
20
|
+
async start() {
|
|
21
|
+
this.stopped = false;
|
|
22
|
+
await this.repo.recoverInterruptedRuns();
|
|
23
|
+
const all = await this.repo.listAll();
|
|
24
|
+
for (const s of all)
|
|
25
|
+
if (s.status === "active")
|
|
26
|
+
this.register(s);
|
|
27
|
+
}
|
|
28
|
+
async stop() {
|
|
29
|
+
this.stopped = true;
|
|
30
|
+
for (const job of this.cronJobs.values())
|
|
31
|
+
job.stop();
|
|
32
|
+
this.cronJobs.clear();
|
|
33
|
+
for (const t of this.pendingRetries.values())
|
|
34
|
+
clearTimeout(t);
|
|
35
|
+
this.pendingRetries.clear();
|
|
36
|
+
for (const ac of this.activeAbort.values()) {
|
|
37
|
+
try {
|
|
38
|
+
ac.abort(new Error("stopping"));
|
|
39
|
+
}
|
|
40
|
+
catch { /* ignore */ }
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
register(s) {
|
|
44
|
+
if (this.cronJobs.has(s.id))
|
|
45
|
+
this.cronJobs.get(s.id).stop();
|
|
46
|
+
const job = new Cron(s.cronExpression, { timezone: s.timezone }, () => {
|
|
47
|
+
void this.tick(s.id);
|
|
48
|
+
});
|
|
49
|
+
this.cronJobs.set(s.id, job);
|
|
50
|
+
}
|
|
51
|
+
unregister(id) {
|
|
52
|
+
this.cronJobs.get(id)?.stop();
|
|
53
|
+
this.cronJobs.delete(id);
|
|
54
|
+
const t = this.pendingRetries.get(id);
|
|
55
|
+
if (t) {
|
|
56
|
+
clearTimeout(t);
|
|
57
|
+
this.pendingRetries.delete(id);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
getRegistered() {
|
|
61
|
+
return Array.from(this.cronJobs.keys());
|
|
62
|
+
}
|
|
63
|
+
// ────────────── Public manual APIs ──────────────
|
|
64
|
+
async triggerNow(id) {
|
|
65
|
+
// Stopped scheduler is a programmer error: throw rather than silently
|
|
66
|
+
// returning a synthetic cancelled run, since most callers will want to
|
|
67
|
+
// see this loud and clear.
|
|
68
|
+
if (this.stopped)
|
|
69
|
+
throw new Error("scheduler stopped");
|
|
70
|
+
const s = await this.repo.getById(id);
|
|
71
|
+
if (!s)
|
|
72
|
+
throw new Error(`Schedule not found: ${id}`);
|
|
73
|
+
// Paused schedule is a runtime condition (UI button on a paused row, or
|
|
74
|
+
// a race with auto-pause). Mirror cwd_busy / previous_run_in_progress and
|
|
75
|
+
// surface it as a synthetic cancelled run rather than throwing — keeps
|
|
76
|
+
// the manual API shape consistent with the cron-fire path.
|
|
77
|
+
if (s.status === "paused") {
|
|
78
|
+
return this.recordCancelled(s, new Date(), "schedule_paused");
|
|
79
|
+
}
|
|
80
|
+
return this.runOnce(s, new Date(), { manualTrigger: true });
|
|
81
|
+
}
|
|
82
|
+
cancel(runId) {
|
|
83
|
+
const ac = this.activeAbort.get(runId);
|
|
84
|
+
if (!ac)
|
|
85
|
+
return false;
|
|
86
|
+
try {
|
|
87
|
+
ac.abort(new Error("cancelled"));
|
|
88
|
+
}
|
|
89
|
+
catch { /* ignore */ }
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
// ────────────── Internal tick / runOnce ──────────────
|
|
93
|
+
async tick(scheduleId) {
|
|
94
|
+
if (this.stopped)
|
|
95
|
+
return;
|
|
96
|
+
try {
|
|
97
|
+
const s = await this.repo.getById(scheduleId);
|
|
98
|
+
if (!s || s.status !== "active")
|
|
99
|
+
return;
|
|
100
|
+
await this.runOnce(s, new Date(), { manualTrigger: false });
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
// eslint-disable-next-line no-console
|
|
104
|
+
console.error("[scheduler] tick failed:", err);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async runOnce(s, scheduledFor, opts) {
|
|
108
|
+
// 1. Single-flight per schedule
|
|
109
|
+
if (this.activeRuns.has(s.id)) {
|
|
110
|
+
const cancelled = await this.recordCancelled(s, scheduledFor, "previous_run_in_progress");
|
|
111
|
+
await this.commitTickPatch(s, this.computeTimestampsPatch(s, scheduledFor));
|
|
112
|
+
return cancelled;
|
|
113
|
+
}
|
|
114
|
+
// 2. cwdLock check — defer with a 60s retry timer if another schedule
|
|
115
|
+
// currently owns the same workDir. Manual triggers fail fast instead.
|
|
116
|
+
const lockOwner = this.cwdLock.get(s.workDir);
|
|
117
|
+
if (lockOwner && lockOwner !== s.id) {
|
|
118
|
+
if (opts.manualTrigger) {
|
|
119
|
+
const cancelled = await this.recordCancelled(s, scheduledFor, "cwd_busy");
|
|
120
|
+
await this.commitTickPatch(s, this.computeTimestampsPatch(s, scheduledFor));
|
|
121
|
+
return cancelled;
|
|
122
|
+
}
|
|
123
|
+
const prior = this.pendingRetries.get(s.id);
|
|
124
|
+
if (prior)
|
|
125
|
+
clearTimeout(prior);
|
|
126
|
+
const timer = setTimeout(() => {
|
|
127
|
+
this.pendingRetries.delete(s.id);
|
|
128
|
+
void this.cwdRetry(s.id, scheduledFor);
|
|
129
|
+
}, CWD_RETRY_MS);
|
|
130
|
+
if (typeof timer.unref === "function") {
|
|
131
|
+
timer.unref();
|
|
132
|
+
}
|
|
133
|
+
this.pendingRetries.set(s.id, timer);
|
|
134
|
+
return this.makeRunRecord(s, scheduledFor, "pending");
|
|
135
|
+
}
|
|
136
|
+
// 3. Acquire locks + create run.
|
|
137
|
+
const run = this.makeRunRecord(s, scheduledFor, "running");
|
|
138
|
+
this.activeRuns.set(s.id, run);
|
|
139
|
+
this.cwdLock.set(s.workDir, s.id);
|
|
140
|
+
await this.repo.appendRun(run);
|
|
141
|
+
this.events.emit("run", run);
|
|
142
|
+
// 4. Pick executor.
|
|
143
|
+
const executor = this.executors[s.mode];
|
|
144
|
+
if (!executor) {
|
|
145
|
+
const failed = await this.finalizeRun(s, run, {
|
|
146
|
+
status: "failed",
|
|
147
|
+
completedAt: new Date().toISOString(),
|
|
148
|
+
error: `no executor for mode ${s.mode}`,
|
|
149
|
+
});
|
|
150
|
+
this.releaseLocks(s, run);
|
|
151
|
+
const patch = await this.computeFinalizationPatch(s, failed, scheduledFor);
|
|
152
|
+
await this.commitTickPatch(s, patch);
|
|
153
|
+
return failed;
|
|
154
|
+
}
|
|
155
|
+
// 5. Invoke executor with timeout + abort controller.
|
|
156
|
+
const abortController = new AbortController();
|
|
157
|
+
this.activeAbort.set(run.id, abortController);
|
|
158
|
+
const stdoutChunks = [];
|
|
159
|
+
const stderrChunks = [];
|
|
160
|
+
const maxRunMs = Math.min(Math.max(1, s.launchConfig.maxRunMs ?? DEFAULT_MAX_RUN_MS), HARD_MAX_RUN_MS);
|
|
161
|
+
const timeoutTimer = setTimeout(() => {
|
|
162
|
+
try {
|
|
163
|
+
abortController.abort(new Error("timeout"));
|
|
164
|
+
}
|
|
165
|
+
catch { /* ignore */ }
|
|
166
|
+
}, maxRunMs);
|
|
167
|
+
if (typeof timeoutTimer.unref === "function") {
|
|
168
|
+
timeoutTimer.unref();
|
|
169
|
+
}
|
|
170
|
+
let result = null;
|
|
171
|
+
let executorError = null;
|
|
172
|
+
try {
|
|
173
|
+
const ctx = {
|
|
174
|
+
schedule: s,
|
|
175
|
+
run,
|
|
176
|
+
signal: abortController.signal,
|
|
177
|
+
onStdout: (chunk) => stdoutChunks.push(chunk),
|
|
178
|
+
onStderr: (chunk) => stderrChunks.push(chunk),
|
|
179
|
+
};
|
|
180
|
+
result = await executor.execute(ctx);
|
|
181
|
+
}
|
|
182
|
+
catch (err) {
|
|
183
|
+
executorError = err instanceof Error ? err : new Error(String(err));
|
|
184
|
+
}
|
|
185
|
+
finally {
|
|
186
|
+
clearTimeout(timeoutTimer);
|
|
187
|
+
this.activeAbort.delete(run.id);
|
|
188
|
+
}
|
|
189
|
+
// 5. Compose final status.
|
|
190
|
+
const completedAt = new Date();
|
|
191
|
+
const durationMs = completedAt.getTime() - new Date(run.startedAt).getTime();
|
|
192
|
+
const finalPatch = composeFinal(abortController, executorError, result);
|
|
193
|
+
const finalized = await this.finalizeRun(s, run, {
|
|
194
|
+
...finalPatch,
|
|
195
|
+
completedAt: completedAt.toISOString(),
|
|
196
|
+
durationMs,
|
|
197
|
+
});
|
|
198
|
+
// 6. Persist logs.
|
|
199
|
+
const stdout = stdoutChunks.join("");
|
|
200
|
+
const stderr = stderrChunks.join("");
|
|
201
|
+
if (stdout.length > 0 || stderr.length > 0) {
|
|
202
|
+
await this.repo.writeRunLogs(s.id, run.id, { stdout, stderr });
|
|
203
|
+
}
|
|
204
|
+
this.releaseLocks(s, run);
|
|
205
|
+
// 7. One combined schedule update: counters (if applicable) + status (if
|
|
206
|
+
// auto-paused by circuit breaker) + lastRunAt + nextRunAt. Single
|
|
207
|
+
// repo.update + single 'change' emit per tick.
|
|
208
|
+
const patch = await this.computeFinalizationPatch(s, finalized, scheduledFor);
|
|
209
|
+
await this.commitTickPatch(s, patch);
|
|
210
|
+
return finalized;
|
|
211
|
+
}
|
|
212
|
+
async cwdRetry(scheduleId, scheduledFor) {
|
|
213
|
+
if (this.stopped)
|
|
214
|
+
return;
|
|
215
|
+
try {
|
|
216
|
+
const s = await this.repo.getById(scheduleId);
|
|
217
|
+
if (!s || s.status !== "active")
|
|
218
|
+
return;
|
|
219
|
+
const owner = this.cwdLock.get(s.workDir);
|
|
220
|
+
if (owner && owner !== s.id) {
|
|
221
|
+
// Still busy → cancel.
|
|
222
|
+
await this.recordCancelled(s, scheduledFor, "cwd_busy");
|
|
223
|
+
await this.commitTickPatch(s, this.computeTimestampsPatch(s, scheduledFor));
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
await this.runOnce(s, scheduledFor, { manualTrigger: false });
|
|
227
|
+
}
|
|
228
|
+
catch (err) {
|
|
229
|
+
// eslint-disable-next-line no-console
|
|
230
|
+
console.error("[scheduler] cwd retry failed:", err);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
// ────────────── Helpers ──────────────
|
|
234
|
+
makeRunRecord(s, scheduledFor, status) {
|
|
235
|
+
const now = new Date();
|
|
236
|
+
return {
|
|
237
|
+
id: ulid(),
|
|
238
|
+
scheduleId: s.id,
|
|
239
|
+
status,
|
|
240
|
+
scheduledFor: scheduledFor.toISOString(),
|
|
241
|
+
startedAt: now.toISOString(),
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
async recordCancelled(s, scheduledFor, reason) {
|
|
245
|
+
const now = new Date();
|
|
246
|
+
const run = {
|
|
247
|
+
id: ulid(),
|
|
248
|
+
scheduleId: s.id,
|
|
249
|
+
status: "cancelled",
|
|
250
|
+
scheduledFor: scheduledFor.toISOString(),
|
|
251
|
+
startedAt: now.toISOString(),
|
|
252
|
+
completedAt: now.toISOString(),
|
|
253
|
+
durationMs: 0,
|
|
254
|
+
error: reason,
|
|
255
|
+
};
|
|
256
|
+
await this.repo.appendRun(run);
|
|
257
|
+
this.events.emit("run", run);
|
|
258
|
+
return run;
|
|
259
|
+
}
|
|
260
|
+
async finalizeRun(s, run, patch) {
|
|
261
|
+
const persisted = await this.repo.updateRun(s.id, run.id, patch);
|
|
262
|
+
const final = persisted ?? { ...run, ...patch };
|
|
263
|
+
this.events.emit("run", final);
|
|
264
|
+
return final;
|
|
265
|
+
}
|
|
266
|
+
releaseLocks(s, run) {
|
|
267
|
+
if (this.activeRuns.get(s.id)?.id === run.id) {
|
|
268
|
+
this.activeRuns.delete(s.id);
|
|
269
|
+
}
|
|
270
|
+
if (this.cwdLock.get(s.workDir) === s.id) {
|
|
271
|
+
this.cwdLock.delete(s.workDir);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Build the combined per-tick patch reflecting the run's outcome:
|
|
276
|
+
* - cancellations: timestamps only (no counter change).
|
|
277
|
+
* - completed: reset counter to 0 (only if it was non-zero).
|
|
278
|
+
* - failed/failed_interrupted: increment counter; if it hits the cap,
|
|
279
|
+
* also flip status → "paused" and skip nextRunAt.
|
|
280
|
+
*/
|
|
281
|
+
async computeFinalizationPatch(s, run, scheduledFor) {
|
|
282
|
+
const cur = await this.repo.getById(s.id);
|
|
283
|
+
if (!cur)
|
|
284
|
+
return this.computeTimestampsPatch(s, scheduledFor);
|
|
285
|
+
const lastRunAt = scheduledFor.toISOString();
|
|
286
|
+
if (run.status === "cancelled") {
|
|
287
|
+
// cancellations do not touch counters.
|
|
288
|
+
return {
|
|
289
|
+
lastRunAt,
|
|
290
|
+
nextRunAt: cur.status === "paused" ? undefined : computeNextRunAt(s),
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
if (run.status === "completed") {
|
|
294
|
+
const patch = {
|
|
295
|
+
lastRunAt,
|
|
296
|
+
nextRunAt: cur.status === "paused" ? undefined : computeNextRunAt(s),
|
|
297
|
+
};
|
|
298
|
+
if (cur.consecutiveFailures !== 0)
|
|
299
|
+
patch.consecutiveFailures = 0;
|
|
300
|
+
return patch;
|
|
301
|
+
}
|
|
302
|
+
// failed / failed_interrupted
|
|
303
|
+
const next = (cur.consecutiveFailures ?? 0) + 1;
|
|
304
|
+
// Defensive: a misconfigured maxConsecutiveFailures of 0 or negative would
|
|
305
|
+
// never trip the breaker — clamp to 1 so the very first failure pauses.
|
|
306
|
+
const max = Math.max(1, cur.maxConsecutiveFailures);
|
|
307
|
+
const willPause = next >= max;
|
|
308
|
+
return {
|
|
309
|
+
consecutiveFailures: next,
|
|
310
|
+
...(willPause ? { status: "paused" } : {}),
|
|
311
|
+
lastRunAt,
|
|
312
|
+
// When (about to be) paused, no future run is scheduled.
|
|
313
|
+
nextRunAt: willPause || cur.status === "paused" ? undefined : computeNextRunAt(s),
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Used by pre-runOnce cancel paths (single-flight, cwd_busy) where there is
|
|
318
|
+
* no executor outcome to feed into counter logic.
|
|
319
|
+
*/
|
|
320
|
+
computeTimestampsPatch(s, scheduledFor) {
|
|
321
|
+
return {
|
|
322
|
+
lastRunAt: scheduledFor.toISOString(),
|
|
323
|
+
nextRunAt: s.status === "paused" ? undefined : computeNextRunAt(s),
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Apply the combined patch with one repo.update + one 'change' emit, and
|
|
328
|
+
* unregister the cron job in between if the schedule was just paused so the
|
|
329
|
+
* emitted snapshot reflects the post-pause state.
|
|
330
|
+
*/
|
|
331
|
+
async commitTickPatch(s, patch) {
|
|
332
|
+
let updated;
|
|
333
|
+
try {
|
|
334
|
+
updated = await this.repo.update(s.id, patch);
|
|
335
|
+
}
|
|
336
|
+
catch {
|
|
337
|
+
// Schedule may have been deleted concurrently — ignore.
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
if (updated.status === "paused") {
|
|
341
|
+
this.unregister(s.id);
|
|
342
|
+
}
|
|
343
|
+
this.events.emit("change", updated);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
function composeFinal(abortController, executorError, result) {
|
|
347
|
+
if (abortController.signal.aborted) {
|
|
348
|
+
const reason = abortController.signal.reason;
|
|
349
|
+
const reasonMsg = reason instanceof Error ? reason.message : String(reason ?? "aborted");
|
|
350
|
+
if (reasonMsg === "cancelled") {
|
|
351
|
+
return { status: "cancelled", error: "cancelled" };
|
|
352
|
+
}
|
|
353
|
+
if (reasonMsg === "timeout") {
|
|
354
|
+
return { status: "failed", error: "timeout" };
|
|
355
|
+
}
|
|
356
|
+
if (reasonMsg === "stopping") {
|
|
357
|
+
return { status: "failed_interrupted", error: "stopping" };
|
|
358
|
+
}
|
|
359
|
+
return { status: "cancelled", error: reasonMsg };
|
|
360
|
+
}
|
|
361
|
+
if (executorError) {
|
|
362
|
+
return { status: "failed", error: executorError.message };
|
|
363
|
+
}
|
|
364
|
+
if (result) {
|
|
365
|
+
if (result.exitCode === 0) {
|
|
366
|
+
return {
|
|
367
|
+
status: "completed",
|
|
368
|
+
exitCode: result.exitCode,
|
|
369
|
+
summary: result.summary,
|
|
370
|
+
swarmId: result.swarmId,
|
|
371
|
+
sessionId: result.sessionId,
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
return {
|
|
375
|
+
status: "failed",
|
|
376
|
+
exitCode: result.exitCode,
|
|
377
|
+
error: result.error ?? `process exited ${result.exitCode}`,
|
|
378
|
+
summary: result.summary,
|
|
379
|
+
swarmId: result.swarmId,
|
|
380
|
+
sessionId: result.sessionId,
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
return { status: "failed", error: "no result" };
|
|
384
|
+
}
|
|
385
|
+
function computeNextRunAt(s) {
|
|
386
|
+
try {
|
|
387
|
+
const next = new Cron(s.cronExpression, { timezone: s.timezone, paused: true })
|
|
388
|
+
.nextRun(new Date());
|
|
389
|
+
return next ? next.toISOString() : undefined;
|
|
390
|
+
}
|
|
391
|
+
catch {
|
|
392
|
+
return undefined;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
//# sourceMappingURL=scheduler-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduler-service.js","sourceRoot":"","sources":["../src/scheduler-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAIL,kBAAkB,EAClB,eAAe,GAChB,MAAM,YAAY,CAAC;AAIpB,MAAM,YAAY,GAA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,CAAC;IAC/C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
export type ScheduleMode = "swarm" | "oneshot";
|
|
2
|
+
export type ScheduleStatus = "active" | "paused";
|
|
3
|
+
export type ScheduleRunStatus = "pending" | "running" | "completed" | "failed" | "failed_interrupted" | "cancelled";
|
|
4
|
+
export interface Schedule {
|
|
5
|
+
id: string;
|
|
6
|
+
agentId: string;
|
|
7
|
+
workDir: string;
|
|
8
|
+
encodedCwd: string;
|
|
9
|
+
label?: string;
|
|
10
|
+
mode: ScheduleMode;
|
|
11
|
+
cronExpression: string;
|
|
12
|
+
timezone: string;
|
|
13
|
+
status: ScheduleStatus;
|
|
14
|
+
consecutiveFailures: number;
|
|
15
|
+
maxConsecutiveFailures: number;
|
|
16
|
+
createdAt: string;
|
|
17
|
+
updatedAt: string;
|
|
18
|
+
lastRunAt?: string;
|
|
19
|
+
nextRunAt?: string;
|
|
20
|
+
launchConfig: ScheduleLaunchConfig;
|
|
21
|
+
}
|
|
22
|
+
export interface ScheduleLaunchConfig {
|
|
23
|
+
prompt: string;
|
|
24
|
+
task?: string;
|
|
25
|
+
swarm?: {
|
|
26
|
+
templateName?: string;
|
|
27
|
+
roles?: string[];
|
|
28
|
+
};
|
|
29
|
+
oneshot?: {
|
|
30
|
+
model?: string;
|
|
31
|
+
maxTurns?: number;
|
|
32
|
+
skipPermissions?: boolean;
|
|
33
|
+
allowedTools?: string[];
|
|
34
|
+
};
|
|
35
|
+
maxRunMs?: number;
|
|
36
|
+
}
|
|
37
|
+
export interface ScheduleRun {
|
|
38
|
+
id: string;
|
|
39
|
+
scheduleId: string;
|
|
40
|
+
status: ScheduleRunStatus;
|
|
41
|
+
scheduledFor: string;
|
|
42
|
+
startedAt: string;
|
|
43
|
+
completedAt?: string;
|
|
44
|
+
durationMs?: number;
|
|
45
|
+
exitCode?: number;
|
|
46
|
+
error?: string;
|
|
47
|
+
summary?: string;
|
|
48
|
+
swarmId?: string;
|
|
49
|
+
sessionId?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface CreateScheduleInput {
|
|
52
|
+
agentId: string;
|
|
53
|
+
workDir: string;
|
|
54
|
+
label?: string;
|
|
55
|
+
mode: ScheduleMode;
|
|
56
|
+
cronExpression: string;
|
|
57
|
+
timezone: string;
|
|
58
|
+
maxConsecutiveFailures?: number;
|
|
59
|
+
launchConfig: ScheduleLaunchConfig;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Patch shape exposed to UI / API callers. Intentionally excludes scheduler
|
|
63
|
+
* bookkeeping fields (`consecutiveFailures`, `lastRunAt`, `nextRunAt`) so a
|
|
64
|
+
* user-facing call can never bypass the failure circuit breaker or rewrite
|
|
65
|
+
* timestamps the scheduler owns.
|
|
66
|
+
*/
|
|
67
|
+
export interface UpdateSchedulePatch {
|
|
68
|
+
label?: string;
|
|
69
|
+
cronExpression?: string;
|
|
70
|
+
timezone?: string;
|
|
71
|
+
status?: ScheduleStatus;
|
|
72
|
+
maxConsecutiveFailures?: number;
|
|
73
|
+
launchConfig?: Partial<ScheduleLaunchConfig>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Patch shape used by SchedulerService internals. Adds scheduler-managed
|
|
77
|
+
* bookkeeping fields on top of the public patch, and is the only shape that
|
|
78
|
+
* may write `consecutiveFailures` / `lastRunAt` / `nextRunAt`.
|
|
79
|
+
*/
|
|
80
|
+
export interface InternalSchedulePatch extends UpdateSchedulePatch {
|
|
81
|
+
consecutiveFailures?: number;
|
|
82
|
+
lastRunAt?: string;
|
|
83
|
+
nextRunAt?: string;
|
|
84
|
+
}
|
|
85
|
+
export declare const DEFAULT_MAX_CONSECUTIVE_FAILURES = 5;
|
|
86
|
+
export declare const DEFAULT_MAX_RUN_MS: number;
|
|
87
|
+
export declare const HARD_MAX_RUN_MS: number;
|
|
88
|
+
export declare const MAX_RUNS_PER_SCHEDULE = 50;
|
|
89
|
+
export declare const MAX_STDOUT_BYTES: number;
|
|
90
|
+
export declare const MAX_STDERR_BYTES: number;
|
|
91
|
+
export declare const MAX_PROMPT_BYTES: number;
|
|
92
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,SAAS,CAAC;AAC/C,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,QAAQ,CAAC;AACjD,MAAM,MAAM,iBAAiB,GACzB,SAAS,GACT,SAAS,GACT,WAAW,GACX,QAAQ,GACR,oBAAoB,GACpB,WAAW,CAAC;AAEhB,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,YAAY,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,cAAc,CAAC;IACvB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,sBAAsB,EAAE,MAAM,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,oBAAoB,CAAC;CACpC;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE;QACN,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;KAClB,CAA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C;CAC9C;AAED;;;;GAIG;AACH,MAAM,WAAW,qBAAsB,SAAQ,mBAAmB;IAChE,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,gCAAgC,IAAI,CAAC;AAClD,eAAO,MAAM,kBAAkB,QAAiB,CAAC;AACjD,eAAO,MAAM,eAAe,QAAsB,CAAC;AACnD,eAAO,MAAM,qBAAqB,KAAK,CAAC;AACxC,eAAO,MAAM,gBAAgB,QAAa,CAAC;AAC3C,eAAO,MAAM,gBAAgB,QAAY,CAAC;AAC1C,eAAO,MAAM,gBAAgB,QAAY,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const DEFAULT_MAX_CONSECUTIVE_FAILURES = 5;
|
|
2
|
+
export const DEFAULT_MAX_RUN_MS = 30 * 60 * 1000; // 30 min, both modes
|
|
3
|
+
export const HARD_MAX_RUN_MS = 24 * 60 * 60 * 1000; // 24 h cap
|
|
4
|
+
export const MAX_RUNS_PER_SCHEDULE = 50;
|
|
5
|
+
export const MAX_STDOUT_BYTES = 256 * 1024;
|
|
6
|
+
export const MAX_STDERR_BYTES = 16 * 1024;
|
|
7
|
+
export const MAX_PROMPT_BYTES = 64 * 1024; // 64 KB cap on launchConfig.prompt
|
|
8
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAiGA,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAAC,CAAC;AAClD,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAK,qBAAqB;AAC3E,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAG,WAAW;AACjE,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACxC,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,GAAG,IAAI,CAAC;AAC3C,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,GAAG,IAAI,CAAC;AAC1C,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,GAAG,IAAI,CAAC,CAAY,mCAAmC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mclawnet/scheduler",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"default": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"./package.json": "./package.json"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"croner": "^10.0.1",
|
|
20
|
+
"ulid": "^2.3.0",
|
|
21
|
+
"@mclawnet/logger": "0.1.5",
|
|
22
|
+
"@mclawnet/task": "0.1.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@sinonjs/fake-timers": "^11.2.2",
|
|
26
|
+
"@types/node": "^22",
|
|
27
|
+
"@types/sinonjs__fake-timers": "^8.1.5",
|
|
28
|
+
"typescript": "^5.8.3",
|
|
29
|
+
"vitest": "^4.0.18"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc",
|
|
33
|
+
"clean": "rm -rf dist",
|
|
34
|
+
"test": "vitest run --retry=2"
|
|
35
|
+
}
|
|
36
|
+
}
|