Skip to content

Schedule activities

Gurmit Teotia edited this page Oct 9, 2017 · 15 revisions

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.

Workflows are generally where you write coordination logic and while in activity you carry out actual work. An activity can take anywhere between a second and days to complete its work. You can learn more about activity hosting and implementation in activity section.

In Guflow you can schedule the activity

public class TranscodeWorkflow : Workflow
{
    public TranscodeWorkflow()
    {
        ScheduleActivity<DownloadActivity>();
    }
}

For workflow to schedule DownloadActivity it must be registered with Amazon SWF. In above version workflow will extract out the activity information from DownloadActivity and schedule it with Amazon SWF when started.

Above API is good if you have access to activity 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");
    }
}

Guflow gives you full control in managing input and events of scheduling activities. Some of following examples will help you to understand the usage of scheduling APIs

//Following example will schedule the DownloadActivity with custom input.
public class TranscodeWorkflow : Workflow
{
    public TranscodeWorkflow()
    {
        ScheduleActivity<DownloadActivity>().WithInput(a=>new {Location ="S3Bucket"});
    }
}
//Following example will reschedule the activity on failure.
public class TranscodeWorkflow : Workflow
{
    public TranscodeWorkflow()
    {
        ScheduleActivity<DownloadActivity>().WithInput(a=>new {Location ="S3Bucket"})
                                            .OnFailure(Reschedule);
    }
}

Scheduling same activity multiple times:

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.

Dependency graph:

You can schedule multiple activities or timer in sequence or in parallel in a workflow. When a workflow starts it will schedule the startup items (activities or timers). Startup items are those which does not have any parent items. Once a activity or timer is completed it will schedule its children.

Clone this wiki locally