Files
payloadcms/test/queues/workflows/parallelTaskWorkflow.ts
Alessio Gravili 7c05c775cb docs: improve jobs autorun docs, adds e2e test (#12196)
This clarifies that jobs.autoRun only *runs* already-queued jobs. It does not queue the jobs for you.

Also adds an e2e test as this functionality had no e2e coverage
2025-06-05 09:19:19 -07:00

38 lines
924 B
TypeScript

import type { WorkflowConfig } from 'payload'
export const parallelTaskWorkflow: WorkflowConfig<'parallelTask'> = {
slug: 'parallelTask',
inputSchema: [
{
name: 'amount',
type: 'number',
required: true,
},
],
handler: async ({ job, inlineTask }) => {
const taskIDs = Array.from({ length: job.input.amount }, (_, i) => i + 1).map((i) =>
i.toString(),
)
await Promise.all(
taskIDs.map(async (taskID) => {
return await inlineTask(`parallel task ${taskID}`, {
task: async ({ req }) => {
const newSimple = await req.payload.db.create({
collection: 'simple',
data: {
title: 'parallel task ' + taskID,
},
})
return {
output: {
simpleID: newSimple.id,
},
}
},
})
}),
)
},
}