如何在 Rails 中实现 rufus-scheduler?
计划正在运行,但出现错误“未定义的方法'do_something'”。有什么不对吗?
使用rails 3.
在 config/initializers/task_scheduler.rb:
require 'rubygems'
require 'rufus/scheduler'
scheduler = Rufus::Scheduler.start_new
scheduler.every("10s") do
JobThing.do_something
end
models/job_thing.rb 中: <代码>
class JobThing < ActiveRecord::Base
def do_something
puts "something"
end
end
ThanksThe schedule is running but errors "undefined method 'do_something'". What is not right?
Using rails 3.
In config/initializers/task_scheduler.rb:
require 'rubygems'
require 'rufus/scheduler'
scheduler = Rufus::Scheduler.start_new
scheduler.every("10s") do
JobThing.do_something
end
models/job_thing.rb:
class JobThing < ActiveRecord::Base def do_something puts "something" end end
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您实际上在 JobThing 类中定义了实例方法时,您正尝试从 task_scheduler 调用类级方法。您可以定义一个类方法,如下所示:
You're trying to call a class-level method from the task_scheduler when you've actually defined an instance method in your JobThing class. You can define a class method as below :