| import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; |
| import { tmpdir } from "node:os"; |
| import { join } from "node:path"; |
| import { describe, expect, it } from "vitest"; |
|
|
| import { SqliteStore } from "../queue/store.js"; |
|
|
| describe("SQLite queue store", () => { |
| it("tracks attempts and exposes the next queued item atomically", () => { |
| const dir = mkdtempSync(join(tmpdir(), "rl-auto-store-")); |
| try { |
| const store = new SqliteStore(join(dir, "tasks.db")); |
| const uploadPath = join(dir, "recording.zip"); |
| writeFileSync(uploadPath, "zip"); |
| const job = store.createJob({}); |
| const item = store.createItem({ |
| jobId: job.id, |
| ord: 1, |
| filename: "recording.zip", |
| uploadPath, |
| detectedMode: "api", |
| }); |
|
|
| const first = store.takeNextQueuedItem(job.id); |
| const second = store.takeNextQueuedItem(job.id); |
|
|
| expect(first?.id).toBe(item.id); |
| expect(first?.status).toBe("running"); |
| expect(first?.attempt_count).toBe(1); |
| expect(first?.last_stage).toBe("running"); |
| expect(second).toBeNull(); |
| store.close(); |
| } finally { |
| rmSync(dir, { recursive: true, force: true }); |
| } |
| }); |
| }); |
|
|