feat: migrate to cloudflare d1 and queues

This commit is contained in:
2025-11-28 16:32:35 +08:00
parent 00e1f82d85
commit bd958fb1ab
19 changed files with 294 additions and 276 deletions

View File

@@ -2,6 +2,10 @@ import { swaggerUI } from "@hono/swagger-ui";
import { OpenAPIHono } from "@hono/zod-openapi";
import { maybeUpdateLastConnectedAt } from "~/controllers/maybeUpdateLastConnectedAt";
import type { QueueName } from "~/libs/tasks/queueName.ts";
import { onNewEpisode } from "./controllers/internal/new-episode";
import type { QueueBody } from "./libs/tasks/queueTask";
const app = new OpenAPIHono();
@@ -65,6 +69,25 @@ app.doc("/openapi.json", {
app.get("/docs", swaggerUI({ url: "/openapi.json" }));
export default app;
export default {
...app,
async queue(batch) {
switch (batch.queue as QueueName) {
case "ANILIST_UPDATES":
batch.retryAll();
break;
case "NEW_EPISODE":
for (const message of (batch as MessageBatch<QueueBody["NEW_EPISODE"]>)
.messages) {
await onNewEpisode(
message.body.aniListId,
message.body.episodeNumber,
);
message.ack();
}
break;
}
},
} satisfies ExportedHandler<Env>;
export { AnilistDurableObject as AnilistDo } from "~/libs/anilist/anilist-do.ts";