From 0d535688ac4b3f7386038ecdfab19a3ffb1a22cc Mon Sep 17 00:00:00 2001 From: nicktrn <55853254+nicktrn@users.noreply.github.com> Date: Wed, 29 Nov 2023 09:28:32 +0000 Subject: [PATCH] Pass jobKey to queueName func --- apps/webapp/app/platform/zodWorker.server.ts | 22 ++++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/apps/webapp/app/platform/zodWorker.server.ts b/apps/webapp/app/platform/zodWorker.server.ts index d25d0302c..d0d148037 100644 --- a/apps/webapp/app/platform/zodWorker.server.ts +++ b/apps/webapp/app/platform/zodWorker.server.ts @@ -60,7 +60,7 @@ const AddJobResultsSchema = z.array(GraphileJobSchema); export type ZodTasks = { [K in keyof TConsumerSchema]: { - queueName?: string | ((payload: z.infer) => string); + queueName?: string | ((payload: z.infer, jobKey?: string) => string); jobKey?: string | ((payload: z.infer) => string | undefined); priority?: number; maxAttempts?: number; @@ -92,8 +92,8 @@ type BatchTaskSpec = TaskSpec & { }; export type ZodWorkerBatchEnqueueOptions = BatchTaskSpec & { - tx?: PrismaClientOrTransaction; - }; + tx?: PrismaClientOrTransaction; +}; export type ZodWorkerEnqueueOptions = TaskSpec & { tx?: PrismaClientOrTransaction; @@ -292,10 +292,6 @@ export class ZodWorker { ...optionsWithoutTx, }; - if (typeof task.queueName === "function") { - spec.queueName = task.queueName(payload); - } - if (typeof task.jobKey === "function") { const jobKey = task.jobKey(payload); @@ -304,6 +300,10 @@ export class ZodWorker { } } + if (typeof task.queueName === "function") { + spec.queueName = task.queueName(payload, spec.jobKey); + } + logger.debug("Enqueuing worker task", { identifier, payload, @@ -346,10 +346,6 @@ export class ZodWorker { ...optionsWithoutTx, }; - if (typeof task.queueName === "function") { - spec.queueName = task.queueName(payload); - } - if (typeof task.jobKey === "function") { const jobKey = task.jobKey(payload); @@ -362,6 +358,10 @@ export class ZodWorker { throw new Error("Failed to enqueue batch job: 'jobKey' can't be empty or undefined"); } + if (typeof task.queueName === "function") { + spec.queueName = task.queueName(payload, spec.jobKey); + } + logger.debug("Enqueuing batch worker task", { identifier, payload,