-
Notifications
You must be signed in to change notification settings - Fork 2
Schedule activities
Note: As of writing this document Guflow allows you to schedule activities and timer in workflow. Supports of child workflows and lambda are coming soon.
Workflow is the place where you-
- Instruct Amazon SWF to schedule activities
- Write coordination logic to schedule the activities
- Write logic to collaborate with other workflows
- Write logic to handle errors in activities.
Workflow logic should be pretty quick in processing the Amazon SWF events and returning the decision back to Amazon SWF. While in activities you carry out actual work. An activity can take anywhere between few milliseconds to days to complete its work. You can learn more about activity hosting and implementation in activity section.
In Guflow you can schedule the activity as shown below:
[WorkflowDescription("1.0")]
public class TranscodeWorkflow : Workflow
{
public TranscodeWorkflow()
{
ScheduleActivity<DownloadActivity>();
}
}
Note: For above code to compile you need to create the DownloadAcitivity class. Please refer to Activity section on how to create activities in Guflow. For workflow to schedule DownloadActivity it must be registered with Amazon SWF. In above example workflow will extract out the activity information from ActivityDescriptionAttribute of DownloadActivity and schedule it with Amazon SWF.
Above API is good if you have access to activity class however if for some reason you don't have access to activity class or your activity is implemented in other framework/language then you can directly provide scheduling information, as shown below:
public class TranscodeWorkflow : Workflow
{
public TranscodeWorkflow()
{
ScheduleActivity(name:"DownloadActivity", version: "1.0");
....
}
}
By default workflow will pass its input to each activity however you have full control on passing the input to activity. You can compose an activity input either from workflow input or from result of another activity or in any other way you like. Following example show various ways to create activity input
[WorkflowDescription("1.0")]
public class TranscodeWorkflow : Workflow
{
public TranscodeWorkflow()
{
ScheduleActivity<DownloadActivity>().WithInput(_=>new {Location= Input.Bucket});
ScheduleActivity<TranscodeActivity>().AfterActivity<DownloadActivity>()
.WithInput(a=>new {InputFile = a.Parent().Result().DownloadedPath});
}
}
Note: Please do not pass huge information in activity input, Amazon SWF has the limitation of 1 MB in request size.
By default workflow will be failed when an activity has failed/timedout however you can configure it to take custom action as shown in following example:
[WorkflowDescription("1.0")]
public class TranscodeWorkflow : Workflow
{
public TranscodeWorkflow()
{
//DownloadActivity will be rescheduled after 2 second timeout, everytime on failure.
ScheduleActivity<DownloadActivity>().WithInput(_=>new {Location= Input.Bucket})
.OnFailure(a=>Reschedule(a).After(TimeSpan.FromSeconds(2));
//TranscodeActivity will be rescheduled immediately on timedout.
ScheduleActivity<TranscodeActivity>().AfterActivity<DownloadActivity>()
.WithInput(a=>new {InputFile = a.Parent().Result().DownloadedPath})
.OnTimeout(Reschedule);
}
}
Both ScheduleActivity methods allow you to pass additional argument - "positional name", which you can use to schedule same activity at different places in a workflow, as shown in following example:
[WorkflowDescription("1.0")]
public class TranscodeWorkflow : Workflow
{
public TranscodeWorkflow()
{
ScheduleActivity<DownloadActivity>().WithInput(_=>new {Location= Input.Bucket});
//TranscodeActivity will be scheduled two times
ScheduleActivity<TranscodeActivity>("MPEGFormat").AfterActivity<DownloadActivity>()
.WithInput(a=>new {Format = "MPEG"});
ScheduleActivity<TranscodeActivity>("WAVFormat").AfterActivity<DownloadActivity>()
.WithInput(a=>new {Format = "WAV"});
}
}
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