Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decision Branching #486

Merged
merged 7 commits into from
Jan 5, 2020
Merged

Decision Branching #486

merged 7 commits into from
Jan 5, 2020

Conversation

danielgerlag
Copy link
Owner

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 somthing 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant