LoadError: Unable to autoload constant (Rails + Sidekiq)

烈酒焚心 提交于 2020-12-12 05:19:15

问题


In my development environement I am getting this error :

WARN: LoadError: Unable to autoload constant Alerts::FailedReportWorker, expected /my-path/app/workers/alerts/failed_report_worker.rb to define it.

I have these workers in my schedule.yml file :

alert_sla_worker:
  cron: "*/1 * * * *"
  class: "Alerts::SlaWorker"
alert_failed_export_worker:
  cron: "*/1 * * * *"
  class: "Alerts::FailedExportWorker"
alert_failed_report_worker:
  cron: "*/1 * * * *"
  class: "Alerts::FailedReportWorker"
alert_failed_extractor_worker:
  cron: "*/1 * * * *"
  class: "Alerts::FailedExtractorWorker"

My folder structure looks like this :

workers
 alerts(folder)
  failed_export_worker.rb
  failed_extractor_worker.rb
  failed_report_worker.rb
  sla_worker.rb

And failed_report_worker.rb :

# frozen_string_literal: true

module Alerts
  class FailedReportWorker
    include Sidekiq::Worker

    sidekiq_options queue: :default, retry: 0

    def perform
        ...
    end
  end
end

How can I fix this issue ? I'm not sure what I'm missing!


回答1:


It may be issue with autoloading... I've faced this type of issue recently. Try to do this: add under workers directory a file named alerts.rb with following code inside:

# frozen_string_literal: true

module Alerts; end

It would be great if it helps



来源:https://stackoverflow.com/questions/61731725/loaderror-unable-to-autoload-constant-rails-sidekiq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!