-
Notifications
You must be signed in to change notification settings - Fork 2
Workflow branches
In a workflow you can schedule multiple lambda functions, activities or timers in parallel or in sequence according to your need. Set of "After.." APIs (e.g. AfterActivity, AfterLambda...) helps you to set up dependencies between lambda functions, activities, child workflow and timers.
Example 1: Let us look at holiday booking workflow in which you want to schedule the activities in the order as shown in following diagram:
BookRoom
|
v
AddDinner
|
v
ChargeCustomer
|
v
SendConfirmation
Above described workflow can be implemented in Guflow as below:
[WorkflowDescription("1.0")]
public class BookHolidaysWorkflow : Workflow
{
public BookHolidaysWorkflow()
{
ScheduleActivity<BookRoom>();
ScheduleActivity<AddDinner>().AfterActivity<BookRoom>();
ScheduleActivity<ChargeCustomer>().AfterActivity<AddDinner>();
ScheduleActivity<SendConfirmation>().AfterActivity<ChargeCustomer>();
}
}
Things to note in above example:
- BookRoom is the startup activity because it does not depends on any other activity or timer. BookRoom activity will be scheduled when workflow started.
- AddDinner activity will be scheduled after "BookRoom" activity as configured by "AfterActivity" API.
- "SendConfirmation" is the last activity in workflow, there are no more children to be scheduled after it, hence workflow will be completed after "SendConfirmation" is successfully completed.
Example 2: Let us now extend the above workflow to support the booking of flights as shown in following diagram:
BookRoom BookFlight
| |
v v
AddDinner ChooseSeat
| |
`````````|```````````
v
ChargeCustomer
|
v
SendConfirmation
You can implement above workflow as shown below:
[WorkflowDescription("1.0")]
public class BookHolidaysWorkflow : Workflow
{
public BookHolidaysWorkflow()
{
ScheduleActivity<BookRoom>();
ScheduleActivity<AddDinner>().AfterActivity<BookRoom>();
ScheduleActivity<BookFlight>();
ScheduleActivity<ChooseSeat>().AfterActivity<BookFlight>();
ScheduleActivity<ChargeCustomer>().AfterActivity<AddDinner>()
.AfterActivity<ChooseSeat>();
ScheduleActivity<SendConfirmation>().AfterActivity<ChargeCustomer>();
}
}
Things to note in above example:
- BookRoom and BookFlight are startup activities and will be scheduled in parallel.
- Up to ChargeCustomer activity, there will be two parallel executing branches of activities.
- ChargeCustomer activity will be scheduled only when both AddDinner and ChooseSeat activities are completed, irrespective of their order of completion.
- After SendConfirmation activity is completed, workflow is marked as completed.
Example 3:
Let us extend the BookHolidaysWorkflow further by including the user choice. e.g. some user my choose to just book hotels while some may book both hotels and flight.
[WorkflowDescription("1.0")]
public class BookHolidaysWorkflow : Workflow
{
public BookHolidaysWorkflow()
{
ScheduleActivity<BookRoom>().When(_=>Input.BookHotel);
ScheduleActivity<AddDinner>().AfterActivity<BookRoom>();
ScheduleActivity<BookFlight>().When(_=>Input.BookFlight);
ScheduleActivity<ChooseSeat>().AfterActivity<BookFlight>();
ScheduleActivity<ChargeCustomer>().AfterActivity<AddDinner>()
.AfterActivity<ChooseSeat>();
ScheduleActivity<SendConfirmation>().AfterActivity<ChargeCustomer>();
}
}
Things to note in above example:
- BookRoom or BookFlight can be schedule together, if user has decided to choose book hotel and flight.
- Only one of the activity BookRoom or BookFlight can be schedule, if user has chosen to book either hotel or flight only.
- ChargeCustomer, in 1st scenario will be scheduled after AddDinner and ChooseSeat activity. While in second 2nd scenario it will not wait for activity which is not going to scheduled. e.g. if user has chosen to book just flight and not hotel then ChargeCustomer will be scheduled after ChooseSeat activity.
Example 4: You can even schedule multiple child after an activity as shown in following diagram:
DownloadFile
|
|`````````````````|
v v
Transcode Transcode
| |
v v
UploadFile UploadFile
| |
`````````|`````````
v
SendConfirmation
Above workflow steps can be implemented as follows:
[WorkflowDescription("1.0")]
public class TranscodeWorkflow : Workflow
{
public TranscodeWorkflow()
{
ScheduleActivity<DownloadFile>();
ScheduleActivity<Transcode>("MP4").AfterActivity<DownloadFile>()
.WithInput(_=>new {Format ="MP4"});
ScheduleActivity<UploadFile>("MP4").AfterActivity<Transcode>("MP4");
ScheduleActivity<Transcode>("WAV").AfterActivity<Download>()
.WithInput(_=>new {Format ="WAV"});
ScheduleActivity<UploadFile>("WAV").AfterActivity<Transcode>("WAV");
ScheduleActivity<SendConfirmation>().AfterActivity<UploadFile>("MP4")
.AfterActivity<UploadFile>("WAV");
}
}
In above example for simplicity it is assumed that all these activities are executing on one machines. TaskListRouting sample shows how to configure the Transcode and UploadFile activity on the machine where DownloadFile was executed.
Workflow branch execution is powered by Deflow algorithm. You can read more about it in next section.
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