macroclaw 0.19.0 → 0.20.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/package.json +1 -1
- package/src/cron.test.ts +10 -5
- package/src/cron.ts +2 -3
package/package.json
CHANGED
package/src/cron.test.ts
CHANGED
|
@@ -254,7 +254,7 @@ describe("CronScheduler", () => {
|
|
|
254
254
|
|
|
255
255
|
it("does not write file when no non-recurring jobs fired", () => {
|
|
256
256
|
writeScheduleConfig({
|
|
257
|
-
jobs: [{ name: "recurring", cron: nonMatchingCron(), prompt: "nope"
|
|
257
|
+
jobs: [{ name: "recurring", cron: nonMatchingCron(), prompt: "nope" }],
|
|
258
258
|
});
|
|
259
259
|
|
|
260
260
|
const onJob = makeOnJob();
|
|
@@ -318,9 +318,9 @@ describe("missed non-recurring events", () => {
|
|
|
318
318
|
expect(onJob).not.toHaveBeenCalled();
|
|
319
319
|
});
|
|
320
320
|
|
|
321
|
-
it("
|
|
321
|
+
it("fires non-recurring job missed by more than 5 minutes", () => {
|
|
322
322
|
writeScheduleConfig({
|
|
323
|
-
jobs: [{ name: "old", cron: minutesAgoCron(10), prompt: "
|
|
323
|
+
jobs: [{ name: "old", cron: minutesAgoCron(10), prompt: "still fires", recurring: false }],
|
|
324
324
|
});
|
|
325
325
|
|
|
326
326
|
const onJob = makeOnJob();
|
|
@@ -328,8 +328,13 @@ describe("missed non-recurring events", () => {
|
|
|
328
328
|
cron.start();
|
|
329
329
|
cron.stop();
|
|
330
330
|
|
|
331
|
-
expect(onJob).
|
|
331
|
+
expect(onJob).toHaveBeenCalledTimes(1);
|
|
332
|
+
const call = onJob.mock.calls[0];
|
|
333
|
+
expect(call[0]).toBe("old");
|
|
334
|
+
expect(call[1]).toContain("[missed event, should have fired");
|
|
335
|
+
expect(call[1]).toContain("still fires");
|
|
336
|
+
|
|
332
337
|
const updated = readScheduleConfig();
|
|
333
|
-
expect(updated.jobs).toHaveLength(
|
|
338
|
+
expect(updated.jobs).toHaveLength(0);
|
|
334
339
|
});
|
|
335
340
|
});
|
package/src/cron.ts
CHANGED
|
@@ -25,7 +25,6 @@ export interface CronSchedulerConfig {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
const TICK_INTERVAL = 10_000; // 10 seconds
|
|
28
|
-
const MISSED_THRESHOLD = 300_000; // 5 minutes
|
|
29
28
|
|
|
30
29
|
export class CronScheduler {
|
|
31
30
|
#lastMinute = -1;
|
|
@@ -88,8 +87,8 @@ export class CronScheduler {
|
|
|
88
87
|
if (job.recurring === false) {
|
|
89
88
|
firedNonRecurring.push(i);
|
|
90
89
|
}
|
|
91
|
-
} else if (job.recurring === false && diff
|
|
92
|
-
// Non-recurring job
|
|
90
|
+
} else if (job.recurring === false && diff >= 60_000) {
|
|
91
|
+
// Non-recurring job in the past — fire regardless of how late
|
|
93
92
|
const missedMinutes = Math.round(diff / 60_000);
|
|
94
93
|
const firedAt = prev.toISOString();
|
|
95
94
|
const missedPrompt = `[missed event, should have fired ${missedMinutes} min ago at ${firedAt}] ${job.prompt}`;
|