Skip to content

Part 1 Create empty workflow

Gurmit Teotia edited this page Aug 31, 2019 · 12 revisions

For this tutorial, I'm assuming you have an account with Amazon AWS:

Create empty workflow:

For ease of learning I have split this tutorial into 4 parts. The objective of this part of the tutorial is to create an empty workflow which will complete immediately when started.

Let us begin with the following steps-

  • Create a .NET console application
  • Install Guflow from nuget repository
Install-Package Guflow
 Or 
dotnet add package Guflow

Now let us create an empty workflow. To create a workflow you need to derive a class from Guflow.Decider.Workflow class and decorate it with WorkflowDescription attribute with the version as required property, as shown below:

[WorkflowDescription("1.0")]
public class TranscodeWorkflow : Workflow
{
}

WorkflowDescriptionAttribute has many other properties, which technically are not required when declaring the workflow but are required to run a workflow in Amazon SWF. So you have two choices-

  • Either provide all the workflow description attributes when declaring the workflow
  • Or provide them when starting the workflow.

For our tutorial we will provide them while declaring the workflow. Here is above code with additional attributes-

[WorkflowDescription("1.0", DefaultChildPolicy = ChildPolicy.Terminate,DefaultTaskListName = "dtasklist",
DefaultExecutionStartToCloseTimeoutInSeconds =10000, DefaultTaskStartToCloseTimeoutInSeconds = 20)]
public class TranscodeWorkflow : Workflow
{
}

In amazon SWF all workflows and activities are registered in a domain and in Guflow SWF's domain is represented by Guflow.Domain class. Following examples shows how to register the domain and workflow with Amazon SWF:

var domain = new Domain(name:"tutorial");
await domain.RegisterAsync(2, "Guflow tutorial");
await domin.RegisterWorkflowAsync<TranscodeWorkflow>();

Now the host the workflows for execution as shown in below example:

using(var hostedWorkflows = domain.Host(new TranscodeWorkflow()))
{
    hostedWorkflows.StartExecution();
    Console.WriteLine("Press any key to terminate");
    Console.ReadKey();
}

Before you run the app, let us configure the AWS credentials for application to call into Amazon SWF. Above code expects the credentials to be provided in App.Config as shown below:

<configuration>
  <appSettings>
     <add key="AWSAccessKey" value="provide your value here"/>
     <add key="AWSSecretKey" value="provide your value here"/>
  </appSettings>
</configuration>

However you can use different constructor of Gufow.Domain class to provide credentials in the way you like.

Now start the console app and if everything is alright it should register the domain and TranscodeWorkflow with Amazon SWF and start polling for any workflow events on default task list-"dtasklist". To see it in action you can log in to Amazon SWF console and start the TranscodeWorkflow therein. Once the workflow is started it should be completed immediately.

Before we finish this part of tutorial, let us change the workflow to fail instead (I'm leaving out properties of WorkflowDescription for clarity):

[WorkflowDescription("1.0")]
public class TranscodeWorkflow : Workflow
{
  [WorkflowEvent(EventName.WorkflowStarted)]
  public WorkflowAction OnStart()
  {
    return FailWorkflow("Empty", "I do not like empty workflow");
  }
}

In the above code, you're invoking OnStart method when the workflow is started and inside it, you're returning a workflow action to fail the workflow. In Guflow, WorkflowEventAttribute is used to handle workflow specific events.

Part-2

Clone this wiki locally