From f48f9810a073f1807e012257ed19ad423d177f75 Mon Sep 17 00:00:00 2001 From: Alessio Gravili Date: Fri, 13 Dec 2024 12:30:38 -0700 Subject: [PATCH] fix: job collection was not added if job config only has workflows and no predefined tasks (#9963) --- packages/payload/src/config/sanitize.ts | 6 ++++- .../src/queues/config/jobsCollection.ts | 26 +++++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/packages/payload/src/config/sanitize.ts b/packages/payload/src/config/sanitize.ts index 4a93e663262..87724c35f00 100644 --- a/packages/payload/src/config/sanitize.ts +++ b/packages/payload/src/config/sanitize.ts @@ -172,7 +172,11 @@ export const sanitizeConfig = async (incomingConfig: Config): Promise 0) { + if ( + (Array.isArray(configWithDefaults.jobs?.tasks) && configWithDefaults.jobs?.tasks?.length) || + (Array.isArray(configWithDefaults.jobs?.workflows) && + configWithDefaults.jobs?.workflows?.length) + ) { let defaultJobsCollection = getDefaultJobsCollection(config as unknown as Config) if (typeof configWithDefaults.jobs.jobsCollectionOverrides === 'function') { diff --git a/packages/payload/src/queues/config/jobsCollection.ts b/packages/payload/src/queues/config/jobsCollection.ts index 88304ff7c01..28bbee498f3 100644 --- a/packages/payload/src/queues/config/jobsCollection.ts +++ b/packages/payload/src/queues/config/jobsCollection.ts @@ -13,18 +13,22 @@ export const getDefaultJobsCollection: (config: Config) => CollectionConfig | nu const workflowSlugs: Set = new Set() const taskSlugs: Set = new Set(['inline']) - config.jobs?.workflows.forEach((workflow) => { - workflowSlugs.add(workflow.slug) - }) + if (config.jobs?.workflows.length) { + config.jobs?.workflows.forEach((workflow) => { + workflowSlugs.add(workflow.slug) + }) + } - config.jobs.tasks.forEach((task) => { - if (workflowSlugs.has(task.slug)) { - throw new Error( - `Task slug "${task.slug}" is already used by a workflow. No tasks are allowed to have the same slug as a workflow.`, - ) - } - taskSlugs.add(task.slug) - }) + if (config.jobs?.tasks.length) { + config.jobs.tasks.forEach((task) => { + if (workflowSlugs.has(task.slug)) { + throw new Error( + `Task slug "${task.slug}" is already used by a workflow. No tasks are allowed to have the same slug as a workflow.`, + ) + } + taskSlugs.add(task.slug) + }) + } const jobsCollection: CollectionConfig = { slug: 'payload-jobs',