gpt4 book ai didi

ruby-on-rails - 创建周期性事件作业失败

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

我正在尝试在 Rails 4.2 中创建一个以正常速率运行的 ActiveJob。作业是第一次被调用,但不会再次启动。我的代码在尝试调用 perform_later 后抛出以下异常。

日志输出

[ActiveJob] Enqueued ProcessInboxJob (Job ID: 76a63689-e330-47a1-af92-8e4838b508ae) to Inline(default)
[ActiveJob] [ProcessInboxJob] [76a63689-e330-47a1-af92-8e4838b508ae] Performing ProcessInboxJob from Inline(default)
ProcessInboxJob running...
[ActiveJob] [ProcessInboxJob] [76a63689-e330-47a1-af92-8e4838b508ae] [AWS S3 200 0.358441 0 retries] list_objects(:bucket_name=>"...",:max_keys=>1000)

[ActiveJob] [ProcessInboxJob] [76a63689-e330-47a1-af92-8e4838b508ae] Enqueued ProcessInboxJob (Job ID: dfd3dd7a-06ab-4dba-9bbf-ce1ad606f7e5) to Inline(default) with arguments: {:wait=>30 seconds}
[ActiveJob] [ProcessInboxJob] [76a63689-e330-47a1-af92-8e4838b508ae] Performed ProcessInboxJob from Inline(default) in 599.72ms
Exiting
/Users/antarrbyrd/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activejob-4.2.0/lib/active_job/arguments.rb:60:in `serialize_argument': Unsupported argument type: ActiveSupport::Duration (ActiveJob::SerializationError)

process_inbox_job.rb

class ProcessInboxJob < ActiveJob::Base
queue_as :default
#FREQUENCY = 3.minutes
def perform()
# do some work
end
# reschedule job
after_perform do |job|
self.class.perform_later(wait: 30.seconds)
end
end

最佳答案

语法是self.class.set(wait: 30.seconds).perform_later。但这不是一种可靠的方法,就好像链中断发生异常一样。您还必须安排初始作业。如果你使用 resque 你可以使用 https://rubygems.org/gems/activejob-scheduler

关于ruby-on-rails - 创建周期性事件作业失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27926863/

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