refactor: decouple Anilist watch status updates from API endpoint to an asynchronous queue worker.
This commit is contained in:
@@ -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 });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user