[英]rufus-scheduler gem not working in rails
I am using the state_machine gem and the rufus-scheduler gem. 我正在使用state_machine gem和rufus-scheduler gem。 State machine is working perfectly.
状态机运行正常。 Rufus-scheduler, however, is not.
但是,Rufus-scheduler不是。 I am building this program just to get used to rufus gem.
我正在建立此程序只是为了适应rufus gem。 10 seconds after :accepted is transitioned to :both, it should then transition to :only_employer.
:accepted转换为:both后10秒钟,则应转换为:only_employer。 However, rufus-scheduler for some reason is not working.
但是,由于某种原因,rufus-scheduler无法正常工作。 The transition to :both works, but then it does not transition to :only_employer.
过渡到:both都可以,但是随后就不能过渡到:only_employer。 How do I fix this?
我该如何解决? Thanks.
谢谢。
class Schedule < ActiveRecord::Base
require 'rufus-scheduler'
scheduler = Rufus::Scheduler.new
def set_schedule
scheduler.in '10' do #documentation says this should be 10 seconds
self.change_to_done
end
end
state_machine :accepted, :initial => :none do
after_transition :any => :both, :do => :set_schedule
event :change_to_done do
transition :both => :only_employer
end
end
end
Using rufus-scheduler for this is overkill. 为此使用rufus-scheduler是过大的。
def set_schedule
Thread.new do
sleep 10
self.change_to_done
end
end
should be sufficient. 应该足够了。
But then is the "server" you run Rails on top of thread-friendly? 但是,是您在线程友好的顶部运行Rails的“服务器”吗? If not, you'd better pass the task to something like resque or sidekick.
如果没有,您最好将任务传递给resque或sidekick之类的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.