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,