on <http://edgeguides.solidus.io/> about state mac...
# support
w
on http://edgeguides.solidus.io/ about state machine is specified that : “…Event subscribers should always be decoupled from the main transaction…” but on solidus
spree/order#finalize
the event
order_finalized
is published on bus at the end of the method. i’m doubtful about the way to go.
c
I think that recommendation still stands, of course there are exceptions to it, you just have to understand the risks. The documentation on state machines highlights some of the potential pitfalls and those would apply to any events you add that trigger synchronous actions - i.e. you could accidentally introduce behaviour that causes a rollback of the transaction.
My preferred way is to introduce new events in an
after_commit
hook wherever possible, because those run outside the main transaction. That is obviously not always possible or ideal, because it may happen multiple times and you may not be able to write your actions in an idempotent way.
If you are subscribing to
order_finalized
and want to ensure that any action you perform doesn’t interfere with the state machine transition, you should ensure that it’s either performed asynchronously or any errors that may be raised by that action are rescued.
w
Yes, there're some events in core that are still published within a db transaction. We need to change it, but it's a tricky situation until we have service objects. For the time being, if possible, I'd publish events in the controller code, even at the cost of repetition.
👍🏼 1
w
Thanks for clarification
👍 1