Unifies pgboss.job (current, per-queue partitioned) and pgboss.archive under one SELECT for operator views. retry promotes archived rows back into the active partition. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
45 lines
1.6 KiB
JavaScript
45 lines
1.6 KiB
JavaScript
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
import { resetDb } from '../helpers/db.js';
|
|
import { migrateUp } from '../../lib/db/migrate.js';
|
|
import { stopBoss, waitForJob } from '../helpers/boss.js';
|
|
import { pool } from '../../lib/db/pool.js';
|
|
import * as queue from '../../lib/jobs/queue.js';
|
|
import { registerWorkers } from '../../lib/jobs/index.js';
|
|
import * as jobs from '../../lib/db/repos/jobs.js';
|
|
|
|
beforeEach(async () => {
|
|
await resetDb(); await migrateUp();
|
|
await queue.start();
|
|
await registerWorkers();
|
|
});
|
|
afterEach(async () => { await stopBoss(); });
|
|
|
|
describe('jobs repo', () => {
|
|
it('list returns recent jobs across states', async () => {
|
|
const id = await queue.enqueue('echo', { ping: 1 });
|
|
await waitForJob('echo', id);
|
|
const rows = await jobs.list({ limit: 10 });
|
|
expect(rows.find(r => r.id === id)).toBeTruthy();
|
|
});
|
|
|
|
it('getById returns null on unknown id', async () => {
|
|
expect(await jobs.getById('00000000-0000-0000-0000-000000000000')).toBeNull();
|
|
});
|
|
|
|
it('retry resubmits a failed job', async () => {
|
|
const id = await queue.enqueue('echo', { ping: 'x' });
|
|
await waitForJob('echo', id);
|
|
// mark it failed directly so retry has something to flip.
|
|
await pool.query(`UPDATE pgboss.job SET state='failed' WHERE id=$1`, [id]);
|
|
const out = await jobs.retry(id);
|
|
expect(out?.state).toBe('retry');
|
|
});
|
|
|
|
it('remove deletes by id', async () => {
|
|
const id = await queue.enqueue('echo', { ping: 'rm' });
|
|
await waitForJob('echo', id);
|
|
await jobs.remove(id);
|
|
expect(await jobs.getById(id)).toBeNull();
|
|
});
|
|
});
|