File size: 1,206 Bytes
c4ae742
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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 });
    }
  });
});