danielgerlag / workflow-core

Lightweight workflow engine for .NET Standard
MIT License
5.33k stars 1.19k forks source link

How to add a workflow as a step to another workflow #1100

Open ksundarkumar opened 1 year ago

ksundarkumar commented 1 year ago

Hello,

I have defined 2 workflows Workflow1 and Workflow2, each of them have their own steps.

I need to execute the Workflow2 after the Workflow1 completes and pass data from last step of Workflow1 to Workflow2 first step.

actually the requirement is to add the Workflow2 as a new step/subflow to Workflow1 dynamically. I am trying to achieve these by Json configuration.

Is it possible to merge/combine two workflows on fly? Please advice

---Workflow1

{
    "Id": "Workflow1",
    "Version": 1,
    "Steps": [
        {
            "Id": "ExtractSender",
            "StepType": "WorkflowCoreConsole.StepsFixed.ExtractSender, WorkflowCoreConsole",
            "NextStepId": "ExtractSubject",
            "Inputs": {
                "MessageDoc": "data"
            }
        }
        {
            "Id": "ExtractSubject",
            "StepType": "WorkflowCoreConsole.StepsFixed.ExtractSubject, WorkflowCoreConsole",          
            "Inputs": {
                "MessageDoc": "data"
            }
        }
    ]
}

---Workflow2

{
    "Id": "Workflow2",
    "Version": 1,
    "Steps": [

        {
            "Id": "BlackList",
            "StepType": "WorkflowCoreConsole.Steps.BlackList, WorkflowCoreConsole",
            "NextStepId": "ExtractReceipent",
            "Inputs": {
                "MessageDoc": "data"
            }
        },
        {
            "Id": "ExtractReceipent",
            "StepType": "WorkflowCoreConsole.StepsFixed.ExtractReceipent, WorkflowCoreConsole",          
            "Inputs": {
                "MessageDoc": "data"
            }
        }
    ]
}
murtoza commented 1 year ago

You can easily do it by creating a new action called NestedWorkflowAction and using this action in Workflow1. This is a little bit complex but possible.

FritzHerbers commented 1 year ago

@ksundarkumar We are just starting with workflow-core. This is a requirements for us to call "global" workflows from workflows. Have you solved this issue and show us your implementation?

VictorioBerra commented 1 year ago

@FritzHerbers Maybe you could use Middleware instead? Or maybe you could use events?