Persisting state in state machine

40 views
Skip to first unread message

Kenneth Avner

unread,
Nov 22, 2016, 6:05:42 AM11/22/16
to masstransit-discuss
I have a problem with a particular state machine not persisting the current state. I am using Entity Framework.
When debugging the instance inline, I can see that the state field on the instance is updated as expected. 

But when the code leaves the state machine, the state at that time is not persisted to the database.

- Is there any special limitations or potential problems I should be aware of here, and how should I go about debugging this most efficiently?
- How about deletion of instances? Are instances that are "Finalized" not deleted? Can I safely delete them, and initialize new ones with the same ID later on if need be?

The transaction type is serialized.


            During(Approving,
                    When(MatchesDecided, and => and.Data.HasNoConfirmedMatches())
                        .TransitionTo(Resolving)
                        .Then(b => DecideIdentity(b, new NewIdentityFromCaseDecision(b.Data.CaseId))),
                    When(MatchesDecided, b => b.Data.HasConfirmedMatches())
                        .TransitionTo(Resolving)))).Then(SEND A MESSAGE - OMITTED);
            During(Resolving,
                    When(IdentityDecided)
                    .Then(PersistIdentityDecisison)
                    .ThenAsync(async context => await context.Publish(new RegistrationBiometryProcessedEvent(context.Data, context.Instance)))
                    .TransitionTo(Archived));
            
            WhenEnter(Archived, b => b.Finalize());

The problem in this code is that the state is never set to "Archived" or "Final". The code actually executes, but nothing is persisted. 

Kenneth Avner

unread,
Nov 22, 2016, 6:22:10 AM11/22/16
to masstransit-discuss
Just to be a bit more specific; the instances are created and persisted, but the later transition to Archived of Finalized is not.

Chris Patterson

unread,
Nov 22, 2016, 8:48:51 AM11/22/16
to masstrans...@googlegroups.com
When you finalize, the state is changed to Final. If you have RemoveWhenFinalized() it will remove the instance. 

__
Chris Patterson




On Tue, Nov 22, 2016 at 3:22 AM -0800, "Kenneth Avner" <ken...@avner.no> wrote:

Just to be a bit more specific; the instances are created and persisted, but the later transition to Archived of Finalized is not.

--
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 post to this group, send email to masstrans...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/9e62ae11-a0f5-43e3-9176-6d7e24214b3f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kenneth Avner

unread,
Nov 22, 2016, 9:21:22 AM11/22/16
to masstransit-discuss
Thanks again,

I have searched the source code for both MassTransit and Automat. but haven't been able to find the RemoveWhenFinalized() method.
Trying to find it by using intuition also failed. Could you please give me a hint on where to look?

-K



tirsdag 22. november 2016 14.48.51 UTC+1 skrev Chris Patterson følgende:
When you finalize, the state is changed to Final. If you have RemoveWhenFinalized() it will remove the instance. 

__
Chris Patterson




On Tue, Nov 22, 2016 at 3:22 AM -0800, "Kenneth Avner" <ken...@avner.no> wrote:

Just to be a bit more specific; the instances are created and persisted, but the later transition to Archived of Finalized is not.

--
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-discuss+unsub...@googlegroups.com.

Kenneth Avner

unread,
Nov 22, 2016, 9:31:27 AM11/22/16
to masstransit-discuss
I found it - I guess you ment SetCompletedWhenFinalized() method on the StateMachine

Chris Patterson

unread,
Nov 22, 2016, 10:54:16 AM11/22/16
to masstrans...@googlegroups.com
Yeah, that's the one :)


--
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-discuss+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages