Iterative Workflow and
What is Iterative Workflow?
An iterative workflow is is a job that mutates during execution, which means that one or more work units are added to it while the job is running.
How is it done?
Creation and submission of dynamic work can be done by a worker at any time during execution.
Worker Initialization
To submit work during execution, the worker will need an instance of the IScheduleWork interface. This can be injected through the worker constructor by defining the constructor as follows:
[ImportingConstructor]
public MyWorker(IScheduleWork scheduleWorkService)
{
this.scheduleWorkService = scheduleWorkService;
}
The scheduleWorkService enables the worker to create and submit any work item to be executed. This work item will then be added to the job and orchestrated by the OneCompute job scheduler.
Dynamic Work Scheduling
A work item can then be created by the worker at any time during execution. The following example shows how to do it from the worker execution method:
public async Task<object> ExecuteAsync(
IWorkerExecutionStatusNotificationService _,
IWorkUnit workUnit,
IEnumerable<Result> dependencyResults)
{
...
var dynamicWork = ... // Create the new work item
await this.scheduleWorkService.ScheduleWorkAsync(workUnit, dynamicWork);
...
}
The first argument to ScheduleWorkAsync is the work unit that generated the new work item (the originating work unit). The second argument represents the new work to be added to the job and can be any work item.
See also
Concepts:
Types: