-
Notifications
You must be signed in to change notification settings - Fork 2
Deflow algorithm
Scheduling of activities, timer or any other child element is powered by Dependency Flow (Deflow) algorithm. Deflow algorithm simplify the writing of complex workflow involving parallel execution branches and let you schedule elements when multiple parallel activities are finished executing.
Deflow algorithm work as described below:
- When a scheduling item is completed then select all of its children to schedule next
- When scheduling an item (activity or timer), ensure that all of its parent branch are inactive
- When jumping down the executing branch, then try to schedule the first joint item as described in step 2
- When an item can not be scheduled because scheduling condition is evaluated to false then try to schedule the first joint item as described in step 2
Above implementation of Deflow algorithm will work very well for many complex scenario, however you can customise any of above step in the workflow.
Lets us look at the following example to understand how Deflow algorithm works. Assume we have a workflow to book the holidays and it schedule the activities as shown below:
In Guflow you can write above workflow as below:
[WorkflowDescription("1.0")]
public class BookHolidaysWorkflow : Workflow
{
public BookHolidaysWorkflow()
{
ScheduleActivity<BookFlight>();
ScheduleActivity<BookFlightFood>().After<BookFlight>();
ScheduleActivity<BookHotel>()
ScheduleActivity<AddDinner>().After<BookHotel>();
ScheduleActivity<ChargeCustomer>().After<BookFlightFood>().After<AddDinner>();
ScheduleActivity<SendEmail>().After<ChargeCustomer>();
}
}
In above workflow BookFlight and BookHotel are the startup activities which will executes in parallel when workflow will start and after their completion their children will be scheduled. ChargeCustomer activity will wait until both branches- 1) BookFlight, BookFlighFood and 2) BookHotel, AddDinner are completed and these branches can complete in any order. SendEmail activity will be scheduled after ChargeCustomer and once it is completed, workflow will be completed too.
Let us modify the above workflow with scheduling conditions:
[WorkflowDescription("1.0")]
public class BookHolidaysWorkflow : Workflow
{
public BookHolidaysWorkflow()
{
ScheduleActivity<BookFlight>().When(a=>Input.BookFlight)
WithInput(a=>Input.BookingId);
ScheduleActivity<BookFlightFood>().After<BookFlight>().When(a=>Input.AddFlightFood)
.WithInput(a=>Input.FlightFoodChoice);
ScheduleActivity<BookHotel>().When(a=>Input.BookHotel);
ScheduleActivity<AddDinner>().After<BookHotel>().When(a=>Input.AddDinner)
.WithInput(a=>Input.DinnerChoice)
ScheduleActivity<ChargeCustomer>().After<BookFlightFood>().After<AddDinner>();
ScheduleActivity<SendEmail>().After<ChargeCustomer>();
}
}
In above example either of branch - 1) BookFlight, BookFlightFood and 2) BookHotel, AddDinner may not be scheduled because of scheduling conditions. When either of active branch reach "ChargeCustomer", workflow will detect that another branch is not active and it will not wait for other branch activities to complete and instead will schedule the ChargeCustomer activity.
Guflow
- Prerequisite
- Installation
-
Workflows
- Creating first workflow
- Registration
- Hosting
- Start workflow
- Schedule activities
- Schedule timers
- Schedule lambda function
- Schedule child workflows
- Lambda functions vs activities
- Workflow input
- Workflow actions
- Signals
- Workflow branches
- Deflow algorithm
- Workflow events
- Query APIs
- Custom polling strategy
- Things to take care of
- Activites
- Unit testing
- Performance & scalability
- Error handling
- Logging
- Debugging
- Tutorial
- Release notes