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秒。
答案 0 :(得分:3)
如果您想要的是运行重复性任务,例如,每天。您可以使用rufus-scheduler:
rufus-scheduler is a Ruby gem for scheduling pieces of code (jobs)
希望它有所帮助!