Workflow Core v3.1.0 Release Notes

Release Date: 2020-01-05 // 24 days ago
  • Workflow Core 3.1

    Decision Branching

    You can define multiple independent branches within your workflow and select one based on an expression value.

    🏗 For the fluent API, we define our branches with the CreateBranch() method on the workflow builder. We can then select a branch using the Decision step.

    This workflow will select branch1 if the value of data.Value1 is one, and branch2 if it is two.

    var branch1 = builder.CreateBranch() .StartWith\<PrintMessage\>() .Input(step =\> step.Message, data =\> "hi from 1") .Then\<PrintMessage\>() .Input(step =\> step.Message, data =\> "bye from 1");var branch2 = builder.CreateBranch() .StartWith\<PrintMessage\>() .Input(step =\> step.Message, data =\> "hi from 2") .Then\<PrintMessage\>() .Input(step =\> step.Message, data =\> "bye from 2");builder .StartWith\<HelloWorld\>() .Decide(data =\> data.Value1) .Branch("one", branch1) .Branch("two", branch2);
    

    The JSON representation would look something like this.

    { "Id": "DecisionWorkflow", "Version": 1, "DataType": "MyApp.MyData, MyApp", "Steps": [{ "Id": "decide", "StepType": "WorkflowCore.Primitives.Decide, WorkflowCore", "Inputs": { "Expression": "data.Value1" }, "OutcomeSteps": { "Print1": "\"one\"", "Print2": "\"two\"" } }, { "Id": "Print1", "StepType": "MyApp.PrintMessage, MyApp", "Inputs": { "Message": "\"Hello from 1\"" } }, { "Id": "Print2", "StepType": "MyApp.PrintMessage, MyApp", "Inputs": { "Message": "\"Hello from 2\"" } }] }
    

    Outcomes for JSON workflows

    You can now specify OutcomeSteps for a step in JSON and YAML workflow definitions.

    "OutcomeSteps":
    {
        "<<Step1 Id>>": "<<expression>>",
        "<<Step2 Id>>": "<<expression>>"
    }
    

    ⏱ If the outcome of a step matches a particular expression, that step would be scheduled as the next step to execute.


Previous changes from v3.0.0

  • Workflow Core 3.0.0

    👌 Support for PostgeSQL is delayed because of this issue with upstream libraries

    📦 Split DSL into own package

    📦 The JSON and YAML definition features into their own package.

    Migration required for existing projects:

    • 📦 Install the WorkflowCore.DSL package from nuget.
    • Call AddWorkflowDSL() on your service collection.

    Activities

    An activity is defined as an item on an external queue of work, that a workflow can wait for.

    In this example the workflow will wait for activity-1, before proceeding. It also passes the value of data.Value1 to the activity, it then maps the result of the activity to data.Value2.

    👷 Then we create a worker to process the queue of activity items. It uses the GetPendingActivity method to get an activity and the data that a workflow is waiting for.

    public class ActivityWorkflow : IWorkflow\<MyData\> { public void Build(IWorkflowBuilder\<MyData\> builder) { builder .StartWith\<HelloWorld\>() .Activity("activity-1", (data) =\> data.Value1) .Output(data =\> data.Value2, step =\> step.Result) .Then\<PrintMessage\>() .Input(step =\> step.Message, data =\> data.Value2); } } ...var activity = host.GetPendingActivity("activity-1", "worker1", TimeSpan.FromMinutes(1)).Result;if (activity != null) { Console.WriteLine(activity.Parameters); host.SubmitActivitySuccess(activity.Token, "Some response data"); }
    

    The JSON representation of this step would look like this

    { "Id": "activity-step", "StepType": "WorkflowCore.Primitives.Activity, WorkflowCore", "Inputs": { "ActivityName": "\"activity-1\"", "Parameters": "data.Value1" }, "Outputs": { "Value2": "step.Result" } }