Skip to content

Commit

Permalink
fix: job collection was not added if job config only has workflows an…
Browse files Browse the repository at this point in the history
…d no predefined tasks (#9963)
  • Loading branch information
AlessioGr authored Dec 13, 2024
1 parent 1502e09 commit f48f981
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
6 changes: 5 additions & 1 deletion packages/payload/src/config/sanitize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,11 @@ export const sanitizeConfig = async (incomingConfig: Config): Promise<SanitizedC
config.i18n = i18nConfig

// Need to add default jobs collection before locked documents collections
if (Array.isArray(configWithDefaults.jobs?.tasks) && configWithDefaults.jobs.tasks.length > 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') {
Expand Down
26 changes: 15 additions & 11 deletions packages/payload/src/queues/config/jobsCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@ export const getDefaultJobsCollection: (config: Config) => CollectionConfig | nu
const workflowSlugs: Set<string> = new Set()
const taskSlugs: Set<string> = 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',
Expand Down

0 comments on commit f48f981

Please sign in to comment.