Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+72
@@ -0,0 +1,72 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
getQueueMonitorSnapshot,
|
||||
pauseQueue,
|
||||
resumeQueue,
|
||||
retryQueueJob,
|
||||
type QueueInspector,
|
||||
type QueueMonitorDeps,
|
||||
} from "./queue-monitor.server";
|
||||
|
||||
function makeInspector(): QueueInspector {
|
||||
return {
|
||||
getCounts: vi.fn(async () => ({ active: 1, waiting: 2, delayed: 0, failed: 3, completed: 4, paused: false })),
|
||||
listFailedJobs: vi.fn(async () => []),
|
||||
pauseQueue: vi.fn(async () => {}),
|
||||
resumeQueue: vi.fn(async () => {}),
|
||||
retryJob: vi.fn(async () => {}),
|
||||
};
|
||||
}
|
||||
|
||||
function makeDeps(inspector: QueueInspector, queueNames: readonly string[]): {
|
||||
deps: QueueMonitorDeps;
|
||||
recordAction: ReturnType<typeof vi.fn>;
|
||||
} {
|
||||
const recordAction = vi.fn(async () => {});
|
||||
return { deps: { inspector, queueNames, recordAction }, recordAction };
|
||||
}
|
||||
|
||||
describe("getQueueMonitorSnapshot", () => {
|
||||
it("gathers counts per queue and resolves the worker group", async () => {
|
||||
const inspector = makeInspector();
|
||||
const { deps } = makeDeps(inspector, ["hivegrid.email", "hivegrid.imports"]);
|
||||
const rows = await getQueueMonitorSnapshot(deps);
|
||||
expect(rows).toHaveLength(2);
|
||||
expect(rows[0]).toMatchObject({ queueName: "hivegrid.email", failed: 3, paused: false });
|
||||
expect(rows[0].group).toBeTypeOf("string");
|
||||
expect(inspector.getCounts).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it("falls back to the general group for an unknown queue name", async () => {
|
||||
const inspector = makeInspector();
|
||||
const { deps } = makeDeps(inspector, ["totally.unknown.queue"]);
|
||||
const rows = await getQueueMonitorSnapshot(deps);
|
||||
expect(rows[0].group).toBe("general");
|
||||
});
|
||||
});
|
||||
|
||||
describe("queue controls", () => {
|
||||
it("pauseQueue calls the inspector and audits queue.paused", async () => {
|
||||
const inspector = makeInspector();
|
||||
const { deps, recordAction } = makeDeps(inspector, ["hivegrid.email"]);
|
||||
await pauseQueue({ queueName: "hivegrid.email", actorUserId: "a1" }, deps);
|
||||
expect(inspector.pauseQueue).toHaveBeenCalledWith("hivegrid.email");
|
||||
expect(recordAction.mock.calls[0][0]).toMatchObject({ action: "queue.paused", targetKind: "queue", targetId: "hivegrid.email" });
|
||||
});
|
||||
|
||||
it("resumeQueue calls the inspector and audits queue.resumed", async () => {
|
||||
const inspector = makeInspector();
|
||||
const { deps, recordAction } = makeDeps(inspector, ["hivegrid.email"]);
|
||||
await resumeQueue({ queueName: "hivegrid.email", actorUserId: "a1" }, deps);
|
||||
expect(inspector.resumeQueue).toHaveBeenCalledOnce();
|
||||
expect(recordAction.mock.calls[0][0]).toMatchObject({ action: "queue.resumed" });
|
||||
});
|
||||
|
||||
it("retryQueueJob retries the job and audits with the jobId", async () => {
|
||||
const inspector = makeInspector();
|
||||
const { deps, recordAction } = makeDeps(inspector, ["hivegrid.email"]);
|
||||
await retryQueueJob({ queueName: "hivegrid.email", jobId: "job-7", actorUserId: "a1" }, deps);
|
||||
expect(inspector.retryJob).toHaveBeenCalledWith("hivegrid.email", "job-7");
|
||||
expect(recordAction.mock.calls[0][0]).toMatchObject({ action: "queue.jobRetried", after: { queueName: "hivegrid.email", jobId: "job-7" } });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user