【问题标题】:Sidekiq 3.4.2 and Rails 4.2.0 having error with 'undefined method perform_at'Sidekiq 3.4.2 和 Rails 4.2.0 出现“未定义方法 perform_at”错误
【发布时间】:2015-11-08 01:02:09
【问题描述】:

我有前任的工作课程

class TempJob < ActiveJob::Base
    queue_as :default # To Do Design Queue

    around_perform do |job, block|
        puts "Before Perform'

        block.call

        puts "After Perform"
    end

    def perform(*args)
        puts "Job Start"
    end
end

我正在尝试将作业安排为从现在开始 1 小时后执行

TempJob.perform_at(1.hour.from_now)

但它给了我以下错误

NoMethodError: undefined method `perform_at' for TempJob:Class

使用 Rails 4.2.0、Ruby 2.2.0 和 Sidekiq 3.4.2。

【问题讨论】:

  • 请不要在问题顶部添加您的设置详细信息,我已经将它们移到了底部。

标签: ruby-on-rails ruby sidekiq ruby-2.2


【解决方案1】:

perform_at是Sidekiq提供的方法名,不是ActiveJob。如果您想使用 ActiveJob 安排作业在相对时间运行,则应使用 ActiveJob's set 方法,如下所示:

TempJob.set(wait: 1.hour).perform_later

还可以查看ActiveJob basics guide

【讨论】:

    猜你喜欢
    • 2017-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多