Lifecycle of StateMachine's state

35 views
Skip to first unread message

Jason Yu

unread,
Oct 27, 2019, 10:58:10 PM10/27/19
to masstransit-discuss
It seems that there is no documentation on what is/should be the lifecycle of a StateMachine's state

Seems there are mix comment about what to do when StateMachine is done.
https://groups.google.com/d/msg/masstransit-discuss/qDUXyl3VzHQ/ddvZYrPZBwAJ
If you want to have your saga in some custom "Completed" state at the end, and not being removed, you can just remove "Finalize()". 
transition to the built in stat final in combination of SetCompletedWhenFinalized is the most common way.

From my understanding
  1. Initial state, set up by Initially()
  2. Custom Automatonymous.State for your StateMachine
  3. Final state, enter when .Finalize is called
  4. Complete state, enter if there is SetCompletedWhenFinalized()
Is it a must to go to final or complete state when ending a StateMachine?
Any impact if we don't go to finalize/complete the StateMachine and let it persist in the db?
Any "best practice" for using the State?

Chris Patterson

unread,
Oct 28, 2019, 7:33:21 AM10/28/19
to masstrans...@googlegroups.com
A state machine can end up in any state you want, Final is just the built-in one for "all done." As you pointed out, it's only removed from the repository if RemoveWhenFinalized is specified.

The only impact is your database size, and performance if you haven't created sufficient indices for the database tables and correlation expressions.

Why use `State` as a property in your instance? Use either a string or an int, and specify it using the InstanceState() configuration method.


--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/0216a1d7-c52b-4a82-b329-5ed703dbf38c%40googlegroups.com.

Jason Yu

unread,
Oct 28, 2019, 11:37:09 PM10/28/19
to masstransit-discuss
So, there is no performance impact if we choose to not use Final or no "complete" and remove the record from the database?
We can just leave the record there for persistence after we are done with that instance and there will be no impact to the StateMachine performance?


Chris Patterson於 2019年10月28日星期一 UTC+8下午7時33分21秒寫道:
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.

Chris Patterson

unread,
Oct 29, 2019, 10:24:26 AM10/29/19
to masstrans...@googlegroups.com
Correct.



Chris Patterson於 2019年10月28日星期一 UTC+8下午7時33分21秒寫道:
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/c6c5ff0f-d375-4431-9bd7-5f80c3b3bc8f%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages