Skip to content

Workflow registration

Gurmit Teotia edited this page Jul 15, 2020 · 15 revisions

Domain

In Amazon SWF you register all the workflows and activities under a domain. It is completely up to you on what basis you create these domains. e.g. one of the possibility is to create the domain based on environments- testing, qa or production. In Guflow Amazon SWF's domain is represented by Guflow.Domain class.

Guflow.Domain class acts as an entry point when you interact with Amazon SWF from Guflow. It provides methods to register workflows and activities and also domain itself. Following example will register the domain "prod" with Amazon SWF if it is not already registered.

var domain = new Domain("prod",RegionEndpoint.EUWest1)
//register the domain
await domain.RegisterAsync(retentionPeriodInDays:10, description: "Production domain")

Guflow relies on "AWSSDK.SimpleWorkflow" library to communicate with Amazon SWF. In above example we have not provided access key and secret key so "Guflow" will expect that you provide these values in your App.Config file:

<configuration>
   <appSettings>
    <add key="AWSAccessKey" value="Put your value here"/>
    <add key="AWSSecretKey" value="Add secret key here"/>
  </appSettings>
</configuration>

However you have the choice to provide credentials in your code by using different constructor of Domain class as show in the following example:

var domain = new Domain("prod", new AmazonSimpleWorkflowClient(/*pass credential here*/)

Registration

Workflow should to be registered with Amazon SWF for Guflow to execute it. Guflow provided APIs only register the workflows if they are not already registered.

To register the workflow with Amazon SWF Guflow.Domain class provides couple of overloaded methods. One of the following overloaded method will register the workflow with Amazon SWF by reading the properties of WorkflowDescriptionAttribute for TranscodeWorkflow:

await domain.RegisterWorkflowAsync<TranscodeWorkflow>();

Following example shows how you can use WorkflowDescriptionAttribute to provide workflow registration details:

[WorkflowDescription("1.0", Name="TranscodeWorkflow", Description="Will transcode videos",
DefaultTaskListName="FastList", DefaultChildPolicy=ChildPolicy.Abandon)]
public class TranscodeWorkflow : Workflow
{
}

Note: While registering the workflow with Amazon SWF, you have the option to provide workflow properties such as: "Name", "Description", "DefaultTaskListName" etc. Though these properties are must when you're running the workflow but you have the flexibility to supply them at registration time or when you are about to start the workflow.

Dynamic WorkflowDescription

WorkflowDescriptionAttribute will be limiting if you want to change its attribute in different environments. You can provide WorkflowDescription dynamically, completely avoiding WorkflowDescriptionAttribute, as shown in the following example:

public class TranscodeWorkflow : Workflow
{
  public static WorkflowDescription Description=>
            new WorkflowDescription("1.0")
            {
                Name = "test",
                Description = "desc",
                DefaultTaskListName = "tname",
                DefaultExecutionStartToCloseTimeout = TimeSpan.FromSeconds(10),
                DefaultTaskStartToCloseTimeout = TimeSpan.FromSeconds(9),
                DefaultChildPolicy= "policy",
                DefaultLambdaRole ="lambdarole", 
                DefaultTaskPriority =1
            };
}

Guflow will look for any static property/method (without any arguments) with WorkflowDescription as return type to build WorkflowDescription and it will take priority over the WorkflowDescriptionAttribute.

If you need to access config file/database to build WorkflowDescription then it is probably best to create WorkflowDescription with some factory method but it is entirely up to you on how you layout the code. Following code delegates the responsibility of creating the WorkflowDescription to the factory class.

public class TranscodeWorkflow : Workflow
{
  public static WorkflowDescription Description=>
            DescriptionFactory.TranscodeWorkflowDescription();
}

Clone this wiki locally