3
class A < ActiveRecord::Base
  def self.a
    A.first.touch
    delay(run_at: Proc.new{ 10.seconds.from_now }).a
    log.info 'Added job to run at ' + 10.seconds.from_now.to_s
  end

  def self.log
    @log ||= Logger.new 'dj.log'
  end
end

为什么我在工作日志中看到这个:

Added job to run at 2013-04-26 01:04:53 UTC
Added job to run at 2013-04-26 01:04:53 UTC
Added job to run at 2013-04-26 01:04:54 UTC
Added job to run at 2013-04-26 01:04:54 UTC
Added job to run at 2013-04-26 01:04:55 UTC

注意:不分开 10 秒。

4

1 回答 1

3

如果您想要运行重复性任务,例如,每天。您可以使用rufus-scheduler

rufus-scheduler is a Ruby gem for scheduling pieces of code (jobs)

还有一些resquesidekiq的扩展。

希望能帮助到你!

于 2013-04-25T16:06:30.717 回答