在ruby state_machine中触发状态之间的中间转换

时间:2013-01-17 13:19:31

标签: ruby state-machine transitions

我正在使用https://github.com/pluginaweek/state_machine

我的代码是

event :set_running do
 transition any => :runnning
end

event :restart do
 transition :failed => :restarting
end

after_transition :failed => :restarting do |job,transition|
  job.set_running
end

after_transition :restarting => :running do |job,transition|
  job.restart_servers 
=begin 
 this takes some time. and i would like job state to be "restarting" while
 it's restarting servers. but it doesn't happen (i suppose because of transaction) 
 until after_transition :failed => :restarting callback is finished.
 so it actually doesnt happen at all because this callback triggers => :running transition
=end
end

换句话说,我想运行“重启”事件一次,并在它从以下位置转移时触发中间转换:失败到:运行。 我能以某种方式使用state_machine吗?

1 个答案:

答案 0 :(得分:0)

http://rdoc.info/github/pluginaweek/state_machine/master/StateMachine/Integrations/ActiveRecord

现在可以禁用交易:

state_machine :initial => :parked, :use_transactions => false do