gpt4 book ai didi

ruby - 延迟作业 gem 的定期任务

转载 作者:数据小太阳 更新时间:2023-10-29 08:00:33 24 4
gpt4 key购买 nike

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 秒。

最佳答案

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

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

还有一些扩展 resquesidekiq .

希望对您有所帮助!

关于ruby - 延迟作业 gem 的定期任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16205746/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com