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
38 lines
924 B
TypeScript
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,
|
|
},
|
|
}
|
|
},
|
|
})
|
|
}),
|
|
)
|
|
},
|
|
}
|