3

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!

7
  • how does failed_report_worker.rb look like? Commented May 11, 2020 at 14:15
  • @RomanAlekseiev I've edited the original post :)
    – Benjamin
    Commented May 11, 2020 at 14:18
  • Weird that it complains only about that worker. Can you try to restart? Can you double-triple check you don’t have typo in file name or classname?
    – Olkin
    Commented May 11, 2020 at 14:54
  • @Olkin I've already done that :( . My coworkers pulled the code and they have the same issue. Could it be a problem with my autoload configuration ? The weirdest thing is that it doesn't happen every time the worker starts, only like 1 time out of 5....
    – Benjamin
    Commented May 11, 2020 at 14:59
  • Test config.autoload_paths += Dir[config.root.join('app', 'workers', '**/*.rb')] Commented May 11, 2020 at 15:47

1 Answer 1

6

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

2
  • Hey ! It seems like it solved my problem, it's really weird .. I will wait a little to see if the error appears again. And if not I will mark your answer as the solution. Thanks a lot !
    – Benjamin
    Commented May 12, 2020 at 10:35
  • 2
    This requirement seems to be enforced as of Rails 5.2.0. Refer to this SO answer for more details Commented Oct 30, 2020 at 16:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.