本文介绍了LoadError:无法自动加载常量(Rails + Sidekiq)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的开发环境中,出现此错误:
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.
我的schedule.yml文件中有这些工人:
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"
我的文件夹结构如下:
workers
alerts(folder)
failed_export_worker.rb
failed_extractor_worker.rb
failed_report_worker.rb
sla_worker.rb
and failed_report_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!
推荐答案
自动加载可能有问题...我最近遇到过此类问题.尝试这样做:在 workers
目录下添加一个名为 alerts.rb
的文件,其中包含以下代码:
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
这篇关于LoadError:无法自动加载常量(Rails + Sidekiq)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!