remove taskId from optional args of queueTask
This commit is contained in:
@@ -25,8 +25,8 @@ type ScheduleConfig =
|
||||
| { epochTime: number; delay: never };
|
||||
|
||||
interface QueueTaskOptionalArgs {
|
||||
taskId?: string;
|
||||
scheduleConfig?: ScheduleConfig;
|
||||
/** when req is not provided, that means the task is being created locally */
|
||||
req?: HonoRequest;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ export async function queueTask(
|
||||
env: Env,
|
||||
queueName: QueueName,
|
||||
body: QueueBody[QueueName],
|
||||
{ taskId, scheduleConfig, req }: QueueTaskOptionalArgs = {},
|
||||
{ scheduleConfig, req }: QueueTaskOptionalArgs = {},
|
||||
) {
|
||||
const domain = req
|
||||
? getCurrentDomain(req)
|
||||
@@ -58,11 +58,10 @@ export async function queueTask(
|
||||
task: buildTask(
|
||||
projectId,
|
||||
queueName,
|
||||
taskId,
|
||||
scheduleConfig,
|
||||
domain,
|
||||
body,
|
||||
req.header(),
|
||||
req?.header(),
|
||||
),
|
||||
}),
|
||||
method: "POST",
|
||||
@@ -73,11 +72,10 @@ export async function queueTask(
|
||||
function buildTask(
|
||||
projectId: string,
|
||||
queueName: QueueName,
|
||||
taskId: string | undefined,
|
||||
scheduleConfig: ScheduleConfig | undefined,
|
||||
domain: string,
|
||||
body: QueueBody[QueueName],
|
||||
headers: Record<string, string>,
|
||||
headers: Record<string, string> | undefined,
|
||||
) {
|
||||
let scheduleTime: string | undefined;
|
||||
if (scheduleConfig) {
|
||||
@@ -88,11 +86,12 @@ function buildTask(
|
||||
scheduleTime = DateTime.now().plus(delay).toUTC().toISO();
|
||||
}
|
||||
}
|
||||
let taskId: string;
|
||||
|
||||
switch (queueName) {
|
||||
case "new-episode":
|
||||
const { aniListId } = body as QueueBody["new-episode"];
|
||||
taskId ??= buildNewEpisodeTaskId(aniListId);
|
||||
taskId = buildNewEpisodeTaskId(aniListId);
|
||||
|
||||
return {
|
||||
name: `projects/${projectId}/locations/northamerica-northeast1/queues/${queueName}/tasks/${taskId}`,
|
||||
@@ -103,13 +102,13 @@ function buildTask(
|
||||
body: JSON.stringify(body),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"X-Anilist-Token": headers["X-Anilist-Token"],
|
||||
"X-Anilist-Token": headers?.["X-Anilist-Token"],
|
||||
},
|
||||
},
|
||||
};
|
||||
case "anilist":
|
||||
const { deviceId, titleId } = body as QueueBody["anilist"];
|
||||
taskId ??= buildAnilistRetryTaskId(deviceId, titleId);
|
||||
taskId = buildAnilistRetryTaskId(deviceId, titleId);
|
||||
|
||||
return {
|
||||
name: `projects/${projectId}/locations/northamerica-northeast1/queues/${queueName}/tasks/${taskId}`,
|
||||
@@ -120,7 +119,7 @@ function buildTask(
|
||||
body: JSON.stringify(body),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"X-Anilist-Token": headers["X-Anilist-Token"],
|
||||
"X-Anilist-Token": headers?.["X-Anilist-Token"],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user