Pass jobKey to queueName func

This commit is contained in:
nicktrn
2023-11-29 09:28:32 +00:00
parent 175b58ce48
commit 0d535688ac
+11 -11
View File
@@ -60,7 +60,7 @@ const AddJobResultsSchema = z.array(GraphileJobSchema);
export type ZodTasks<TConsumerSchema extends MessageCatalogSchema> = {
[K in keyof TConsumerSchema]: {
queueName?: string | ((payload: z.infer<TConsumerSchema[K]>) => string);
queueName?: string | ((payload: z.infer<TConsumerSchema[K]>, jobKey?: string) => string);
jobKey?: string | ((payload: z.infer<TConsumerSchema[K]>) => 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<TMessageCatalog extends MessageCatalogSchema> {
...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<TMessageCatalog extends MessageCatalogSchema> {
}
}
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<TMessageCatalog extends MessageCatalogSchema> {
...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<TMessageCatalog extends MessageCatalogSchema> {
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,