geekq/workflow — Issue #43: ActiveRecord Transactions
Author: kstevens715
Created: 2012-01-30 14:45:43+00:00
State: open

What I would like is for the event transition and the transition event handler to be executed within the same ActiveRecord transaction to guarantee that the state is properly represented.

I'm using Workflow along with ActiveRecord in an order processing application. I have an event, "confirm", that relieves available inventory and changes the order state from "Processing" to "Shipped". I know if there is a problem confirming inventory I can use halt! to prevent the state from updating to "Shipped". But, what I am concerned of is the rare case in which the error occurs in updating the state itself. If this were to happen, the inventory would confirm but the state would remain "Processing". Then, the same order would be confirmed again the next time the rake task runs which would double-relieve inventory.

I know I could try and catch the exception and try and reverse the effects, but things can start to get complicated when doing that. Is there currently a solution to run the entire event sequence in an ActiveRecord transaction?

Thank you for your help, and btw thanks for this gem... it's almost exactly what I was looking for.