danielduarte / flowed

A fast and reliable flow engine for orchestration and more uses in Node.js, Deno and the browser
https://danielduarte.github.io/flowed
MIT License
151 stars 21 forks source link

Select next task #31

Closed antirek closed 3 years ago

antirek commented 3 years ago

Maybe I don't understand this moment from docs, but can change next task from current?

For example, taskA ended and now result = 1, and now flow go to TaskB, at next time on end TaskA result = 2 and now flow go to TaskC. How I can realize this flow with flowed?

danielduarte commented 3 years ago

Hello @antirek, thanks for your answer.

Flowed offers very useful and detailed debugging information when running flows. To enable and see those details, please run your app with the environment variable DEBUG with the value flowed:*, for example:

DEBUG=flowed:* node .

That instructs Flowed to output debugging info to the standard output. Also there is a way to install a custom debugger so you can manipulate easily that info with FlowManager.installLogger(logger: FlowedLogger).

I still owe the users the documentation for debugging, I'll be working on that soon.

Hope this answer your question. But if it doesn't, don't hesitate in providing some more details for me to understand what are you trying to solve.

antirek commented 3 years ago

Thanks for debuging options, it's very helpful.

But I want choose next flow step, when I got result from task. For example, result of task 'select recipe' is 'salad' and my flow must go to task 'buy cucumber' for salad )). If result of task 'select recipe' is 'cookies' my flow must go to task 'buy sugar'.

Of course, I can use task 'buy anything' and check recipe result and select inside task. But is hidden from flow process. Can I split my flow via flow tasks?

process flow:

danielduarte commented 3 years ago

Oh, now I got exactly what you meant. And the answer is yes, you can split the flow execution to take different branches depending on a condition. By default Flowed provides a special resolver called "flowed::Conditional" for that use case.

So, for example your case would look like this:

image

Where the task "choose recipe" returns the recipe name, and the diamond in the middle evaluates it in the condition. Once the condition is evaluated to true or false, only one of the branches is activated by returning either the trueResult or the falseResult.

Here you have some links that could help:

Also note that if you need a different or custom behavior, the engine support integration with any custom task type where you can implement any other branching or splitting strategy according to your needs.

By the way, there is another new resolver in the Flowed roadmap to deal with multiple options in a decision, kind of a switch/case behavior.

Let me know if you have any other question.

antirek commented 3 years ago

Ok, great thanks. I'll write some code with Conditional resolver ;)