mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-06 15:52:22 +01:00
Merge updated parent into sleep-21-voice-session-recovery
Preserve the existing PR boundary while integrating master through the sleep migration stack. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
commit
af9c8ab9dd
3 files changed
+24
No files matched your search
@@ -102,6 +102,21 @@ const support = external ? { supported: true } : await getEmbeddedPostgresTestSu
|
||||
expect(await runs()).toHaveLength(15);
|
||||
expect(rpc).not.toHaveBeenCalled();
|
||||
});
|
||||
it("honors a saved deadline inside the notification batching window", async () => {
|
||||
const row = await job();
|
||||
const deadline = new Date(Date.now() + 10_000);
|
||||
await pluginJobStore(db).updateRunTimestamps(row.id, new Date(0), deadline);
|
||||
await start();
|
||||
// registerPlugin produces a local wake immediately after startup. It may
|
||||
// batch the reload but must not replace the known ten-second deadline.
|
||||
await settled();
|
||||
expect(coordinator!.nextWakeAt()).toBe(deadline.getTime());
|
||||
expect(rpc).not.toHaveBeenCalled();
|
||||
await vi.advanceTimersByTimeAsync(Math.max(0, deadline.getTime() - Date.now()));
|
||||
await completed();
|
||||
expect(rpc).toHaveBeenCalledOnce();
|
||||
expect(rpc.mock.calls[0][2]).toMatchObject({ job: { scheduledAt: deadline.toISOString() } });
|
||||
});
|
||||
it("keeps configured manual-only and invalid schedules quiet", async () => {
|
||||
await job("manual", ""); await job("invalid", "not cron"); await start(); await quiet(); expect(rpc).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -9,11 +9,14 @@ export function registerDeadlineWork(
|
||||
next: () => Promise<number | null>;
|
||||
canRun: () => boolean;
|
||||
retryMs: number;
|
||||
// Optional batching latency for notifications; already-known deadlines still preempt it.
|
||||
notificationCoalesceMs?: number;
|
||||
},
|
||||
) {
|
||||
let requested = 1, reconciled = 0;
|
||||
let next: number | null = null;
|
||||
let earliest = 0;
|
||||
let coalesceUntil = 0;
|
||||
const worker = coordinator.register(queue, {
|
||||
retryMs: task.retryMs,
|
||||
pausePassiveMaintenance: true,
|
||||
@@ -21,6 +24,10 @@ export function registerDeadlineWork(
|
||||
run: async signal => {
|
||||
if (!task.canRun()) { requested++; return; }
|
||||
if (Date.now() < earliest) { next = earliest; return; }
|
||||
if (Date.now() < coalesceUntil && (next === null || next > Date.now())) {
|
||||
next = next === null ? coalesceUntil : Math.min(next, coalesceUntil);
|
||||
return;
|
||||
}
|
||||
const generation = ++requested;
|
||||
earliest = Date.now() + task.retryMs;
|
||||
await task.run(signal);
|
||||
@@ -29,6 +36,7 @@ export function registerDeadlineWork(
|
||||
// Back off failed or still-overdue work, not a successfully read future deadline.
|
||||
if (deadline === null || deadline > Date.now()) earliest = 0;
|
||||
next = deadline === null ? null : Math.max(earliest, deadline);
|
||||
coalesceUntil = Date.now() + (task.notificationCoalesceMs ?? 0);
|
||||
reconciled = generation;
|
||||
},
|
||||
hasPending: async () => requested !== reconciled,
|
||||
|
||||
@@ -186,6 +186,7 @@ export function createPluginJobScheduler(options: PluginJobSchedulerOptions): Pl
|
||||
running = true;
|
||||
worker = registerDeadlineWork(coordinator, DELIVERY_QUEUES.pluginSchedules, {
|
||||
run: tick, next: async () => next, canRun, retryMs: tickIntervalMs,
|
||||
notificationCoalesceMs: tickIntervalMs,
|
||||
});
|
||||
await worker.ready;
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user