import { Hono } from "hono"; import { onNewEpisode } from "~/jobs/new-episode"; import type { QueueName } from "~/libs/tasks/queueName.ts"; import { maybeUpdateLastConnectedAt } from "~/middleware/maybeUpdateLastConnectedAt"; import type { QueueBody } from "./libs/tasks/queueTask"; export const app = new Hono(); app.use(maybeUpdateLastConnectedAt); // GraphQL endpoint replaces all REST routes app.route( "/graphql", await import("~/graphql").then((module) => module.default), ); export default { fetch: app.fetch, async queue(batch) { switch (batch.queue as QueueName) { case "ANILIST_UPDATES": batch.retryAll(); break; case "NEW_EPISODE": for (const message of (batch as MessageBatch) .messages) { await onNewEpisode( message.body.aniListId, message.body.episodeNumber, ); message.ack(); } break; } }, async scheduled(event, env, ctx) { const { processDelayedTasks } = await import( "~/libs/tasks/processDelayedTasks" ); await processDelayedTasks(env, ctx); }, } satisfies ExportedHandler; export { AnilistDurableObject as AnilistDo } from "~/libs/anilist/anilist-do.ts";