Giter Site home page Giter Site logo

Nested Workflows about workflow-core HOT 17 CLOSED

danielgerlag avatar danielgerlag commented on May 19, 2024
Nested Workflows

from workflow-core.

Comments (17)

danielgerlag avatar danielgerlag commented on May 19, 2024 3
  1. Currently, there is no built in functionality to explicitly nest workflows, but you could compose the aggregate the fluent call chains into variables that you could reuse as sort of "sub-workflows" - However, this is definitely on my radar as a first class feature.

  2. You could write a custom locking step to achieve this but there is no built in feature for it.

from workflow-core.

danielgerlag avatar danielgerlag commented on May 19, 2024 3

Something like this

public void Build(IWorkflowBuilder<MyData> builder)
{
    var branch1 = new Action<IWorkflowBuilder<MyData>>(branch => 
        branch.StartWith<PrintMessage>()
            .Input(step => step.Message, data => "Value is less than 3"));

    var branch2 = new Action<IWorkflowBuilder<MyData>>(branch =>
        branch.StartWith<PrintMessage>()
            .Input(step => step.Message, data => "Value is less than 5"));

    builder
        .StartWith<SayHello>()
        .If(data => data.Counter < 3).Do(branch1)
        .If(data => data.Counter < 5).Do(branch2)
        .Then<SayGoodbye>();
}        

from workflow-core.

ScarletyCapone avatar ScarletyCapone commented on May 19, 2024 1

Is it possible for these branches to utilize different context classes other than "MyData". EX the main workflow use a "MasterWorkflowDataContext" and the branches have "Branch1Context", "Branch2Context", etc. allowing us to pass some data back and forth between the master and branch data context classes? I'd like not to bloat "MyData" with too many properties that only pertain to a branch.

from workflow-core.

ScarletyCapone avatar ScarletyCapone commented on May 19, 2024 1

@danielgerlag Circling back to this finally, did you have any additional thoughts on branches that can utilize different data contexts? Trying to build some reusable branches for common sets of tasks that may be shared among various workflows. The workflows all use different data types, but they all inherit from base classes / interfaces that would be utilized for the branches.

from workflow-core.

alex-vorobyev avatar alex-vorobyev commented on May 19, 2024 1
  1. Currently, there is no built in functionality to explicitly nest workflows, but you could compose the aggregate the fluent call chains into variables that you could reuse as sort of "sub-workflows" - However, this is definitely on my radar as a first class feature.

@danielgerlag so, is native support for nested workflows planned?

from workflow-core.

ewyuen avatar ewyuen commented on May 19, 2024

You mention you can compose the fluent call chains into variables and reuse it. Can you provide an example how to do it?

from workflow-core.

ewyuen avatar ewyuen commented on May 19, 2024

Thank you! It works.

from workflow-core.

danielgerlag avatar danielgerlag commented on May 19, 2024

That's a good suggestion... I will investigate what is involved to implement something like this

from workflow-core.

rose-pace avatar rose-pace commented on May 19, 2024

I have a similar issue but mine relates to working within a loop. Essentially I am pulling a batch of data and looping through it and working on individual messages. Based on message type my logic branches to perform different tasks. In the end I create a new entity that gets saved.

It is cumbersome passing data around via context.Item inside the loop and it would be nice if you could set up a different data class within the loop so I could pass more data between steps than just context.Item.

from workflow-core.

ScarletyCapone avatar ScarletyCapone commented on May 19, 2024

@rosspace Within your loop you still have access to the context class used for the entire workflow, you're not limited to just the item within a collection. So if your context class contains a class to persist data between the steps and a collection of classes for your messages to process, you can still get to everything.

from workflow-core.

rose-pace avatar rose-pace commented on May 19, 2024

@ScarletyCapone but if I'm in a parallel ForEach I could set fields on the context class but wouldn't that not be thread safe? Since other iterations could be running on separate threads couldn't anything I assign be overwritten by another thread between steps? Or are you saying I should be using a While loop and just increment an index of the item I am working on that way I can set whatever I want on the main class?

The while loop approach would work although it would become a synchronous process instead of parallel but that is probably not a problem in my case.

from workflow-core.

ScarletyCapone avatar ScarletyCapone commented on May 19, 2024

@rosspace If I understood right these are not parallel in the essence that they run on different threads; I had the same confusions over in issue 189 that I opened. I also learned this ForEach implementation doesn't iterate as one would think, it will do step 1 for all items in your collection before attempting step 2 for any of them, which is why I moved to a while loop for my solution. I needed to logically process all tasks for item 1 before attempting any for the next.

from workflow-core.

rose-pace avatar rose-pace commented on May 19, 2024

@ScarletyCapone that is good to know. I would not have expected it to work that way. I don't think that would give me an issue but I think I will want to move to the while loop anyways because of the complexity of my workflow.

Thanks!

from workflow-core.

danielgerlag avatar danielgerlag commented on May 19, 2024

@ScarletyCapone I have not spent much time on this yet but I think it is worthwhile

from workflow-core.

gonengf avatar gonengf commented on May 19, 2024

I also think that would be great to have branches to utilize different context classes

There is no way at this point to pass a specific object in a ForEach loop to a re-usable sub-workflow apart from using one in the main data context class.

CORRECTION:

I could access the looped object under the sub-workflow using:

  Action<IWorkflowBuilder<ModuleCompareWorkflowData>> installWorkflow = new Action<IWorkflowBuilder<ModuleCompareWorkflowData>>(workflow =>
                workflow.StartWith<LogMessageStep>()
                    .Input(step => step.Message, (data, context) => ((ModuleToInstall)context.Item).Name));

from workflow-core.

danielgerlag avatar danielgerlag commented on May 19, 2024

#486

from workflow-core.

mitbilal avatar mitbilal commented on May 19, 2024
        builder
            .StartWith<WorkFlowStarted>()
            .WaitFor("MyEvent1", (data, context) => "Key", data => DateTime.Now)
                .Output(data => data.Value1, step => step.EventData)
            .Then((context) =>
            {
                return ExecutionResult.Next();
            })
            .Decide(data => data.Value1)
                .Branch((data, outcome) => data.Value1.ToLower() == CValue.ToLower(), level1User1);

from workflow-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.