feat: allow running sub-tasks from tasks (#10373)
Task handlers now receive `inlineTask` as an arg, which can be used to
run inline sub-tasks. In the task log, those inline tasks will have a
`parent` property that points to the parent task.
Example:
```ts
{
slug: 'subTask',
inputSchema: [
{
name: 'message',
type: 'text',
required: true,
},
],
handler: async ({ job, inlineTask }) => {
await inlineTask('create two docs', {
task: async ({ input, inlineTask }) => {
const { newSimple } = await inlineTask('create doc 1', {
task: async ({ req }) => {
const newSimple = await req.payload.create({
collection: 'simple',
req,
data: {
title: input.message,
},
})
return {
output: {
newSimple,
},
}
},
})
const { newSimple2 } = await inlineTask('create doc 2', {
task: async ({ req }) => {
const newSimple2 = await req.payload.create({
collection: 'simple',
req,
data: {
title: input.message,
},
})
return {
output: {
newSimple2,
},
}
},
})
return {
output: {
simpleID1: newSimple.id,
simpleID2: newSimple2.id,
},
}
},
input: {
message: job.input.message,
},
})
},
} as WorkflowConfig<'subTask'>
```
Job log example:
```ts
[
{
executedAt: '2025-01-06T03:55:44.682Z',
completedAt: '2025-01-06T03:55:44.684Z',
taskSlug: 'inline',
taskID: 'create doc 1',
output: { newSimple: [Object] },
parent: { taskSlug: 'inline', taskID: 'create two docs' }, // <= New
state: 'succeeded',
id: '677b5440ba35d345d1214d1b'
},
{
executedAt: '2025-01-06T03:55:44.690Z',
completedAt: '2025-01-06T03:55:44.692Z',
taskSlug: 'inline',
taskID: 'create doc 2',
output: { newSimple2: [Object] },
parent: { taskSlug: 'inline', taskID: 'create two docs' }, // <= New
state: 'succeeded',
id: '677b5440ba35d345d1214d1c'
},
{
executedAt: '2025-01-06T03:55:44.681Z',
completedAt: '2025-01-06T03:55:44.697Z',
taskSlug: 'inline',
taskID: 'create two docs',
input: { message: 'hello!' },
output: {
simpleID1: '677b54401e34772cc63c8693',
simpleID2: '677b54401e34772cc63c8697'
},
parent: {},
state: 'succeeded',
id: '677b5440ba35d345d1214d1d'
}
]
```