jondot / sneakers

A fast background processing framework for Ruby and RabbitMQ
https://github.com/jondot/sneakers
MIT License
2.24k stars 333 forks source link

Use application's configured loader for eager loading #472

Closed MatthewRDodds closed 1 year ago

MatthewRDodds commented 1 year ago

We ran into an issue while running the latest from the master branch of sneakers, which includes https://github.com/jondot/sneakers/pull/411. This application is Rails 6 and uses the classic autoloader implementation, not Zeitwerk. When we installed another gem recently that uses Zeitwerk, our bundle exec rake sneakers:run task began resulting in this message:

Error: No workers found.
Please set the classes of the workers you want to run like so:

  $ export WORKERS=MyWorker,FooWorker
  $ rake sneakers:run

You can also configure them with
  $ Sneakers.rake_worker_classes

If you use something that responds to :call it will execute that

Eventually, if nothing before applied, every class is used where you directly included the Sneakers::Worker

Since this other gem we installed uses Zeitwerk, it brought in the dependency, and the Zeitwerk constant became defined. Using ::Rails.application.eager_load! successfully loads our worker classes as expected.

michaelklishin commented 1 year ago

Thank you.