fix: cloud tasks not being queued and failing silently

This commit is contained in:
2024-10-14 08:28:22 +08:00
parent 91dd250823
commit 37cf7bd738
2 changed files with 12 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ import { DateTime, type DurationLike } from "luxon";
import type { Env } from "~/types/env";
import type { WatchStatus } from "~/types/title/watchStatus";
import { FailedToQueueTaskError } from "../errors/FailedToQueueTask";
import { getAdminSdkCredentials } from "../gcloud/getAdminSdkCredentials";
import { getGoogleAuthToken } from "../gcloud/getGoogleAuthToken";
import { getCurrentDomain } from "../getCurrentDomain";
@@ -47,7 +48,7 @@ export async function queueTask(
const adminSdkCredentials = getAdminSdkCredentials(env);
const { projectId } = adminSdkCredentials;
await fetch(
const res = await fetch(
`https://content-cloudtasks.googleapis.com/v2/projects/${projectId}/locations/northamerica-northeast1/queues/${queueName}/tasks?alt=json`,
{
headers: {
@@ -67,6 +68,10 @@ export async function queueTask(
method: "POST",
},
);
if (!res.ok) {
throw new FailedToQueueTaskError(res.status, await res.text());
}
}
function buildTask(
@@ -99,7 +104,7 @@ function buildTask(
httpRequest: {
url: `${domain}/internal/new-episode`,
httpMethod: "POST",
body: JSON.stringify(body),
body: Buffer.from(JSON.stringify(body)).toString("base64"),
headers: {
"Content-Type": "application/json",
"X-Anilist-Token": headers?.["X-Anilist-Token"],