-
-
Notifications
You must be signed in to change notification settings - Fork 102
Passing data / input / output between States (Workflow automation use case) #468
-
Hi! I've started to use this lib for a project because it seems very packed for what I'd like to do: simple Workflow execution.
But I couldn't find in the docs a clear explanation of how to handle data passing or sharing between states which seems basic compared to what the library offers, that's why I find it strange I couldn't easily find it. As an example, I'd like to make sure that before transitioning into a specific state, certain data is being passed so that further States / Transitions that depend on that data can proceed. Thank you!
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 2 replies
-
Hi @sevetseh28,
How are you?
Could you provide a concrete or even a toy example? I'm unsure if you're asking about passing information in an event for use in actions or storing additional data that can be used later.
There is an example of a Guess the Number Machine where the number of guesses is stored in the state machine instance, and the attempt number is passed as a positional argument into the guess event trigger.
In this example, the state machine is attached to a dataclass. Notice how we pass a token in the signup event trigger.
Let me know if this helps.
Best regards!
Beta Was this translation helpful? Give feedback.
All reactions
-
Hey Fernando :)
Thanks for the quick reply. My use case is basically a Workflow execution , so it's just a subset of a State machine, or a special case of a State machine. My workflow is pretty linear with only a few branchings based on certain conditions.
And as with any Workflow execution, my Nodes (states) will receive an input from the previous node, and pass an output to the next Node. I'd like to type these with strict type hints to have a clear contract between the States and let MyPy catch these.
I'm not currently with my machine but can write an example once I Get back to it.
So you suggest using the event methods to pass my own arguments ? I think that may work.
Thanks !
Beta Was this translation helpful? Give feedback.
All reactions
-
One thing that I didn't mention is that I'd also like my workflow to run automatically (i.e. execute some kind of .run method and just let it start the execution and resolve which transitions it will go to based on the conditions defined and I couldn't see what is the best practice for this. Should the State themselves send an event? from the examples I always saw an external caller explicitly call an event.
Beta Was this translation helpful? Give feedback.