开发者

How to implement rufus-scheduler in Rails?

开发者 https://www.devze.com 2023-03-09 21:02 出处:网络
The schedule is running but errors \"undefined method \'do_something\'\". What is not right? Using rails 3.

The 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_ne开发者_StackOverflow社区w
scheduler.every("10s") do
    JobThing.do_something
end

models/job_thing.rb:

class JobThing < ActiveRecord::Base
    def do_something
        puts "something"
    end 
end
Thanks


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 :

class JobThing < ActiveRecord::Base
  def self.do_something
    puts "something"
  end
end
0

精彩评论

暂无评论...
验证码 换一张
取 消