feat: migrate to cloudflare d1 and queues
This commit is contained in:
25
src/index.ts
25
src/index.ts
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user