diff --git a/src/libs/tasks/queueTask.spec.ts b/src/libs/tasks/queueTask.spec.ts index d5d6c92..f893af6 100644 --- a/src/libs/tasks/queueTask.spec.ts +++ b/src/libs/tasks/queueTask.spec.ts @@ -35,8 +35,8 @@ describe("queueTask - delayed task handling", () => { (globalThis as any).crypto = { randomUUID: vi.fn(() => "test-uuid-123") }; }); - describe("tasks with delay <= 12 hours", () => { - it("queues task directly when delay is less than 12 hours", async () => { + describe("tasks with delay <= 9 hours", () => { + it("queues task directly when delay is less than 9 hours", async () => { await queueTask( "NEW_EPISODE", { aniListId: 123, episodeNumber: 1 }, @@ -52,12 +52,12 @@ describe("queueTask - delayed task handling", () => { expect(kvPutSpy).not.toHaveBeenCalled(); }); - it("queues task directly when delay is exactly 12 hours", async () => { + it("queues task directly when delay is exactly 9 hours", async () => { await queueTask( "NEW_EPISODE", { aniListId: 456, episodeNumber: 2 }, { - scheduleConfig: { delay: { hours: 12 } }, + scheduleConfig: { delay: { hours: 9 } }, env: mockEnv, }, ); @@ -81,8 +81,8 @@ describe("queueTask - delayed task handling", () => { }); }); - describe("tasks with delay > 12 hours", () => { - it("stores task in KV when delay exceeds 12 hours", async () => { + describe("tasks with delay > 9 hours", () => { + it("stores task in KV when delay exceeds 9 hours", async () => { await queueTask( "NEW_EPISODE", { aniListId: 111, episodeNumber: 4 }, @@ -98,12 +98,12 @@ describe("queueTask - delayed task handling", () => { expect(queueSendSpy).not.toHaveBeenCalled(); }); - it("stores task in KV when delay is 12 hours + 1 second", async () => { + it("stores task in KV when delay is 9 hours + 1 second", async () => { await queueTask( "NEW_EPISODE", { aniListId: 222, episodeNumber: 5 }, { - scheduleConfig: { delay: { hours: 12, seconds: 1 } }, + scheduleConfig: { delay: { hours: 9, seconds: 1 } }, env: mockEnv, }, ); @@ -176,7 +176,7 @@ describe("queueTask - delayed task handling", () => { }); describe("epoch time scheduling", () => { - it("queues directly when epoch time is within 12 hours", async () => { + it("queues directly when epoch time is within 9 hours", async () => { const futureTime = Math.floor(Date.now() / 1000) + 3600; // 1 hour from now await queueTask( @@ -192,7 +192,7 @@ describe("queueTask - delayed task handling", () => { expect(kvPutSpy).not.toHaveBeenCalled(); }); - it("stores in KV when epoch time is beyond 12 hours", async () => { + it("stores in KV when epoch time is beyond 9 hours", async () => { const futureTime = Math.floor(Date.now() / 1000) + 24 * 3600; // 24 hours from now await queueTask( diff --git a/src/libs/tasks/queueTask.ts b/src/libs/tasks/queueTask.ts index e8307c7..e1ff0e5 100644 --- a/src/libs/tasks/queueTask.ts +++ b/src/libs/tasks/queueTask.ts @@ -40,17 +40,16 @@ export async function queueTask( req?.header(), ); - const MAX_DELAY_SECONDS = 12 * 60 * 60; // 43,200 seconds (12 hours) + const MAX_DELAY_SECONDS = Duration.fromObject({ hours: 9 }).as("seconds"); - // If delay exceeds 12 hours, store in KV for later processing + // If delay exceeds 9 hours, store in KV for later processing if (scheduleTime > MAX_DELAY_SECONDS) { if (!env || !env.DELAYED_TASKS) { throw new Error("DELAYED_TASKS KV namespace not available"); } - const { generateTaskKey, serializeDelayedTask } = await import( - "./delayedTask" - ); + const { generateTaskKey, serializeDelayedTask } = + await import("./delayedTask"); const taskId = crypto.randomUUID(); const scheduledEpochTime = Math.floor(Date.now() / 1000) + scheduleTime;