diff --git a/packages/payload/src/queues/config/jobsCollection.ts b/packages/payload/src/queues/config/jobsCollection.ts index b8bc6ab5354..a311d2b7bf9 100644 --- a/packages/payload/src/queues/config/jobsCollection.ts +++ b/packages/payload/src/queues/config/jobsCollection.ts @@ -1,5 +1,6 @@ import type { CollectionConfig } from '../../collections/config/types.js' import type { Config } from '../../config/types.js' +import type { Field } from '../../fields/config/types.js' import { runJobsEndpoint } from '../restEndpointRun.js' import { getJobTaskStatus } from '../utilities/getJobTaskStatus.js' @@ -14,7 +15,7 @@ export const getDefaultJobsCollection: (config: Config) => CollectionConfig | nu const queueNames: Set = new Set(['default']) - config.jobs.workflows.forEach((workflow) => { + config.jobs?.workflows.forEach((workflow) => { workflowSlugs.add(workflow.slug) if (workflow.queue) { @@ -141,16 +142,20 @@ export const getDefaultJobsCollection: (config: Config) => CollectionConfig | nu }, ], }, - { - name: 'workflowSlug', - type: 'select', - admin: { - position: 'sidebar', - }, - index: true, - options: [...workflowSlugs], - required: false, - }, + // only include the workflowSlugs field if workflows exist + ...((workflowSlugs.size > 0 + ? [ + { + name: 'workflowSlug', + type: 'select', + admin: { + position: 'sidebar', + }, + index: true, + options: [...workflowSlugs], + }, + ] + : []) as Field[]), { name: 'taskSlug', type: 'select', diff --git a/packages/payload/src/queues/config/types/index.ts b/packages/payload/src/queues/config/types/index.ts index 33704a62813..31e48f0dcb9 100644 --- a/packages/payload/src/queues/config/types/index.ts +++ b/packages/payload/src/queues/config/types/index.ts @@ -41,5 +41,5 @@ export type JobsConfig = { /** * Define all the workflows here. Workflows orchestrate the flow of multiple tasks. */ - workflows: WorkflowConfig[] + workflows?: WorkflowConfig[] } diff --git a/packages/payload/src/queues/operations/runJobs/index.ts b/packages/payload/src/queues/operations/runJobs/index.ts index cfca8032d0a..3f5fa29ff94 100644 --- a/packages/payload/src/queues/operations/runJobs/index.ts +++ b/packages/payload/src/queues/operations/runJobs/index.ts @@ -138,7 +138,7 @@ export const runJobs = async ({ const jobReq = isolateObjectProperty(req, 'transactionID') const workflowConfig: WorkflowConfig = job.workflowSlug - ? req.payload.config.jobs.workflows.find(({ slug }) => slug === job.workflowSlug) + ? req.payload.config.jobs?.workflows.find(({ slug }) => slug === job.workflowSlug) : { slug: 'singleTask', handler: async ({ job, tasks }) => {