Create tasks
Durable create tasks is a step that can be used to create one or more sub tasks. Tasks are not waited for, once the tasks are successfully created, the step is completed. It is possible to wait for the completion of created tasks using the Wait for external events step.
Tasks are created in a durable way, initialization of the tasks only occurs once. When all tasks are created, the step is considered completed and will not be retried. When one or more tasks fail to create, no tasks are created or started.
API reference:
Required scopes:
Data/Buildby.Taskurai/steps/create
Optional scopes:
Data/Buildby.Taskurai/sensitive/read: Can return sensitive data.Data/Buildby.Taskurai/secrets/read: Can read global secrets.
Prerequisites
- You have completed the setup of a worker in Taskurai, see Workers and Commands.
Creating multiple tasks
In this same, two tasks are created at the same time. The following sample creates two SendDailySalesApproval tasks after 30 seconds, including a state reference to a report, generated in a previous step and stored as a blob.
- C#
var sendDailApprovalStep = await context.CreateTasksAsync(
"send-daily-sales-approval-step",
init: (response, taskConfigs) =>
{
taskConfigs.Add(new TaskConfig("SendDailySalesApproval")
{
Arguments = {
new TaskArgument("fullName")
{
Value = approverUS.FullName
},
new TaskArgument("toEmail")
{
Value = approverUS.Email
},
new TaskArgument("taskId")
{
Value = context.Task.Id
},
new TaskArgument("sumDailySales")
{
Value = sumDailySales
},
new TaskArgument("eventname")
{
Value = "managerUSApprovalEvent"
},
new TaskArgument("report")
{
StateReference = salesReportResponse.Outputs.GetStateReference()
}
},
ExecutionOptions = new TaskExecutionOptions()
{
StartAfter = new After()
{
Seconds = 30
}
}
});
taskConfigs.Add(new TaskConfig("SendDailySalesApproval")
{
Arguments = {
new TaskArgument("fullName")
{
Value = approverEU.FullName
},
new TaskArgument("toEmail")
{
Value = approverEU.Email
},
new TaskArgument("taskId")
{
Value = context.Task.Id
},
new TaskArgument("sumDailySales")
{
Value = sumDailySales
},
new TaskArgument("eventname")
{
Value = "managerEUApprovalEvent"
},
new TaskArgument("report")
{
StateReference = salesReportResponse.Outputs.GetStateReference()
}
},
ExecutionOptions = new TaskExecutionOptions()
{
StartAfter = new After()
{
Seconds = 30
}
}
});
}
);
Creating a single task
It is possible to create one task at a time. The following sample creates a task SendDailySalesApproval after 30 seconds, including a state reference to a report, generated in a previous step and stored as a blob.
- C#
var sendDailySalesApprovalStep = await context.CreateTaskAsync(
"send-daily-sales-approval-step",
init: (response) =>
{
return new TaskConfig("SendDailySalesApproval")
{
Arguments = {
new TaskArgument("fullName")
{
Value = approver.FullName
},
new TaskArgument("toEmail")
{
Value = approver.Email
},
new TaskArgument("taskId")
{
Value = context.Task.Id
},
new TaskArgument("sumDailySales")
{
Value = sumDailySales
},
new TaskArgument("eventname")
{
Value = "managerApprovalEvent"
},
new TaskArgument("report")
{
StateReference = salesReportResponse.Outputs.GetStateReference()
}
},
ExecutionOptions = new TaskExecutionOptions()
{
StartAfter = new After()
{
Seconds = 30
}
}
};
}
);