我有一个名为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)中调用此工作程序,如下所示:
class NewReleasesController < ApplicationController
def index
ReleaseMonitorAddWorker.perform_async
end
end
我启动redis,然后启动sidekiq,然后运行rails。触发该控制器方法时出现以下错误:uninitialized constant NewReleasesController::ReleaseMonitorAddWorker
这是怎么回事?
答案 0 :(得分:2)
您的类名(ReleaseMonitorAddWorker
)和包含的文件名(release_monitor_worker.rb
)之间不匹配。将文件重命名为release_monitor_add_worker.rb
或将类重命名为ReleaseMonitorWorker
都可以。