transitions icon indicating copy to clipboard operation
transitions copied to clipboard

Add "failure" callback to defined events

Open jondecko opened this issue 11 years ago • 5 comments

Initial discussion started in the following issue ( https://github.com/troessner/transitions/issues/113 )

Like the success callback on events, we should have a matching failure callback. An event definition may look something like the following:

event :available, :failure => :reorder do
  transitions :to => :available, :from => [:out_of_stock], :guard => lambda { |product| product.in_stock > 0 }
end

The failure callback should take the following:

  • symbol or lambda block like many other callbacks within the gem
  • single callback or an array of callbacks like the rest of the gem

A few areas to consider where a failure condition may come into play

  • The state does not transition because you are moving from one state that can't move to another state (to -> from's are not valid)
  • A guard condition is hit preventing a successful transition
  • An on_transition scenario halts the transition from being successful. An exception may be raised within an on_transition callback.

@troessner - Let me know if anything looks out of line with the initial plan for this.

jondecko avatar Dec 24 '13 15:12 jondecko

Excellent summary. One more thing: i think right now the "success" callback is more of an "execute at the end" callback. I dont think we are checking there for any success whatsoever. Just saying that we might need to change the flow there as well.

troessner avatar Dec 24 '13 15:12 troessner

Sounds good. I'll have to check for that condition when I crack into the code a bit more :)

jondecko avatar Dec 24 '13 15:12 jondecko

@troessner - Have not forgot about this but still have not had time to get into it. Just wanted to give you a heads up on this.

jondecko avatar Jan 18 '14 05:01 jondecko

No problem, noted..:)

troessner avatar Jan 18 '14 08:01 troessner

+1

pedromartinez avatar May 01 '14 15:05 pedromartinez