fix: cloud tasks not being queued and failing silently
This commit is contained in:
5
src/libs/errors/FailedToQueueTask.ts
Normal file
5
src/libs/errors/FailedToQueueTask.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export class FailedToQueueTaskError extends Error {
|
||||
constructor(status: number, bodyText: string) {
|
||||
super(`Failed to queue task; status: ${status}, body: ${bodyText}`);
|
||||
}
|
||||
}
|
||||
@@ -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"],
|
||||
|
||||
Reference in New Issue
Block a user