LoadError: Unable to autoload constant (Rails + Sidekiq)

LoadError: Unable to autoload constant (Rails + Sidekiq)

在我的开发环境中,我遇到了这个错误:

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

我的 schedule.yml 档案中有这些工人:

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"

我的文件夹结构如下所示:

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

和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

我该如何解决这个问题?我不确定我错过了什么!

这可能是自动加载的问题...我最近遇到过此类问题。 尝试这样做: 在 workers 目录下添加一个名为 alerts.rb 的文件,其中包含以下代码:

# frozen_string_literal: true

module Alerts; end

如果有帮助那就太好了