fix(core): reaper skips own in-flight jobs, heartbeat, no attempt burned on shutdown
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
839d9697b0
commit
f0d41f23c8
2 files changed
+63
-9
No files matched your search
@@ -145,6 +145,41 @@ forEachDialect("jobs", (getDb) => {
|
||||
err.mockRestore();
|
||||
});
|
||||
|
||||
test("a job running past staleMs is not reaped by its own worker and runs once", async () => {
|
||||
const db = getDb();
|
||||
const id = (await enqueue(db, "t", {}, { lockKey: "slow" }))!;
|
||||
let runs = 0;
|
||||
const w = startWorker(db, { t: async () => { runs++; await sleep(300); } }, { pollMs: 10, staleMs: 50, heartbeatMs: 20 });
|
||||
await until(async () => (await row(db, id)).status === "done");
|
||||
await w.stop();
|
||||
expect(runs).toBe(1);
|
||||
});
|
||||
|
||||
test("heartbeat refreshes locked_at", async () => {
|
||||
const db = getDb();
|
||||
const id = (await enqueue(db, "t", {}))!;
|
||||
let release!: () => void;
|
||||
const gate = new Promise<void>((r) => (release = r));
|
||||
const w = startWorker(db, { t: () => gate }, { pollMs: 10, heartbeatMs: 20 });
|
||||
await until(async () => (await row(db, id)).status === "running");
|
||||
const first = (await row(db, id)).locked_at!;
|
||||
await until(async () => (await row(db, id)).locked_at !== first);
|
||||
expect((await row(db, id)).locked_at).not.toBe(first);
|
||||
release();
|
||||
await w.stop();
|
||||
});
|
||||
|
||||
test("stop() re-queues an aborted job without burning an attempt or backoff", async () => {
|
||||
const db = getDb();
|
||||
const id = (await enqueue(db, "t", {}))!;
|
||||
const before = (await row(db, id)).run_at;
|
||||
let started = false;
|
||||
const w = startWorker(db, { t: (_p, { signal }) => new Promise<void>((_, rej) => { started = true; signal.addEventListener("abort", () => rej(new Error("aborted"))); }) }, { pollMs: 10 });
|
||||
await until(async () => started);
|
||||
await w.stop();
|
||||
expect(await row(db, id)).toMatchObject({ status: "queued", attempts: 0, run_at: before, locked_at: null });
|
||||
});
|
||||
|
||||
test("stop() aborts the signal handed to handlers", async () => {
|
||||
const db = getDb();
|
||||
await enqueue(db, "t", {});
|
||||
|
||||
Reference in new issue
Block a user