Created
December 13, 2010 06:50
-
-
Save rwz/738734 to your computer and use it in GitHub Desktop.
state_machine + delayed_job wtf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# doesn't fucking work | |
class Logo < ActiveRecord::Base | |
state_machine :state, :initial => :initial do | |
# here vvv | |
after_transition :initial => :used, :do => :test_callback | |
# here ^^^ | |
event :use do | |
transition :initial => :used | |
end | |
end | |
def test_callback | |
raise 'Fuck' | |
end | |
handle_asynchronously :test_callback | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# works | |
class Logo < ActiveRecord::Base | |
state_machine :state, :initial => :initial do | |
# here vvv | |
after_transition :initial => :used do |logo, t| | |
logo.test_callback | |
end | |
# here ^^^ | |
event :use do | |
transition :initial => :used | |
end | |
end | |
def test_callback | |
raise 'Fuck' | |
end | |
handle_asynchronously :test_callback | |
end |
thank you!!!! fucking fuck! :)
Thank you.
you rock
Thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found this in google, I know it's old, but if you never figured it out: I assume
handle_asynchronously
is hooking your callback method in a way that the original method is still being called when you use the:do => :callback
syntax in the state machine. In the block you are calling it directly, allowing whatever aliasing is going on behind the scenes in DelayedJob to work.