refactor: decouple Anilist watch status updates from API endpoint to an asynchronous queue worker.

This commit is contained in:
2025-12-16 08:28:33 -05:00
parent 1501aff3b6
commit 80a6f67ead
5 changed files with 43 additions and 80 deletions

View File

@@ -16,8 +16,6 @@ import {
} from "~/types/schema";
import { WatchStatus } from "~/types/title/watchStatus";
import { maybeUpdateWatchStatusOnAnilist } from "./anilist";
const app = new OpenAPIHono<Cloudflare.Env>();
const UpdateWatchStatusRequest = z.object({
@@ -109,30 +107,16 @@ app.openapi(route, async (c) => {
}
}
try {
await maybeUpdateWatchStatusOnAnilist(
Number(titleId),
await queueTask(
"ANILIST_UPDATES",
{
deviceId,
watchStatus,
aniListToken,
);
} catch (error) {
console.error("Failed to update watch status on Anilist");
console.error(error);
if (isRetrying) {
return c.json(ErrorResponse, { status: 500 });
}
await queueTask(
"ANILIST_UPDATES",
{
deviceId,
watchStatus,
titleId,
updateType: AnilistUpdateType.UpdateWatchStatus,
},
{ req: c.req, scheduleConfig: { delay: { minute: 1 } } },
);
}
titleId,
updateType: AnilistUpdateType.UpdateWatchStatus,
},
{ req: c.req, scheduleConfig: { delay: { minute: 1 } } },
);
return c.json(SuccessResponse, { status: 200 });
});