The task run logic. It is similar to the run
function in DurableTaskOptions but it
returns the output and children tasks to be run in parallel after the run function completes.
Optional
finalizeTask?: DurableFinalizeTaskOptions<TInput, TRunOutput, TOutput, TFinalizeTaskRunOutput>Task to run after the runParent function and children tasks complete. This is useful for combining the output of the run function and children tasks.
const extractFileTitle = executor
.inputSchema(v.object({ filePath: v.string() }))
.task({
id: 'extractFileTitle',
timeoutMs: 30_000, // 30 seconds
run: async (ctx, input) => {
// ... extract the file title
return {
title: 'File Title',
}
},
})
const summarizeFile = executor
.validateInput(async (input: { filePath: string }) => {
if (!isValidFilePath(input.filePath)) {
throw new Error('Invalid file path')
}
return {
filePath: input.filePath,
}
})
.task({
id: 'summarizeFile',
timeoutMs: 30_000, // 30 seconds
run: async (ctx, input) => {
// ... summarize the file
return {
summary: 'File summary',
}
},
})
const uploadFile = executor
.inputSchema(v.object({ filePath: v.string(), uploadUrl: v.string() }))
.parentTask({
id: 'uploadFile',
timeoutMs: 60_000, // 1 minute
runParent: async (ctx, input) => {
// ... upload file to the given uploadUrl
// Extract the file title and summarize the file in parallel
return {
output: {
filePath: input.filePath,
uploadUrl: input.uploadUrl,
fileSize: 100,
},
childrenTasks: [
{
task: extractFileTitle,
input: { filePath: input.filePath },
},
{
task: summarizeFile,
input: { filePath: input.filePath },
},
],
}
},
finalizeTask: {
id: 'onUploadFileAndChildrenComplete',
timeoutMs: 60_000, // 1 minute
run: async (ctx, { input, output, childrenTasksOutputs }) => {
// ... combine the output of the run function and children tasks
return {
filePath: input.filePath,
uploadUrl: input.uploadUrl,
fileSize: 100,
title: 'File Title',
summary: 'File summary',
}
}
},
})
Options for a durable parent task that can be run using a durable executor. It is similar to DurableTaskOptions but it returns children tasks to be run in parallel after the run function completes, along with the output of the parent task.
The runParent function is similar to the
run
function in DurableTaskOptions, but the output is of the form{ output: TRunOutput, childrenTasks: Array<DurableChildTask> }
where the children are the tasks to be run in parallel after the run function completes.The finalizeTask task is run after the runParent function and all the children tasks complete. It is useful for combining the output of the runParent function and children tasks. It's input has the following properties:
input
: The input of thefinalizeTask
task. Same as the input of runParent functionoutput
: The output of the runParent functionchildrenTasksOutputs
: The outputs of the children tasksIf finalizeTask is provided, the output of the whole task is the output of the finalizeTask task. If it is not provided, the output of the whole task is the output of the form
{ output: TRunOutput, childrenTasksOutputs: Array<DurableChildTaskExecutionOutput> }
.See the task examples section for more details on creating tasks.