【问题标题】:Rails 5.2 and Sidekiq: Can't find Worker ClassRails 5.2 和 Sidekiq:找不到工人阶级
【发布时间】:2018-10-03 17:06:07
【问题描述】:

我有一个名为release_monitor_worker.rb 的工人保存在app/workers/ 下。看起来像这样:

class ReleaseMonitorAddWorker
  include Sidekiq::Worker
  sidekiq_options retry: false

  require 'watir'
  require 'nokogiri'
  require 'open-uri'

  def parse_url(url)
    puts "Beginning navigation to #{url}"
    browser = Watir::Browser.new :chrome, headless: true
    browser.goto url
    puts "Succesfully navigated!"
    Nokogiri::HTML.parse(browser.html)
  end

  def perform
    doc = parse_url(URL)
    count = doc.xpath('/html/body/div[9]/div/div/div/div/div[2]/div[2]/div[1]/div/div[1]/h1/span')
    count.tr('()', '')
    binding.pry
  end
end

然后我从我的 NewReleasesController(名为 new_releases_controller.rb)中调用这个 worker,如下所示:

class NewReleasesController < ApplicationController
  def index
    ReleaseMonitorAddWorker.perform_async
  end
end

我启动 redis,然后启动 sidekiq,然后运行 ​​rails s。触发该控制器方法时出现以下错误:uninitialized constant NewReleasesController::ReleaseMonitorAddWorker

这是怎么回事?

【问题讨论】:

    标签: ruby-on-rails redis sidekiq


    【解决方案1】:

    您的类名 (ReleaseMonitorAddWorker) 和包含的文件名 (release_monitor_worker.rb) 不匹配。将您的文件重命名为release_monitor_add_worker.rb 或将您的班级重命名为ReleaseMonitorWorker,它将起作用。

    【讨论】:

      猜你喜欢
      • 2018-01-18
      • 2015-05-17
      • 1970-01-01
      • 2018-01-02
      • 2018-08-29
      • 2015-01-03
      • 1970-01-01
      • 2016-04-10
      • 1970-01-01
      相关资源
      最近更新 更多