-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto-loading consumers from a Rails 6 app requires using classic autoloader #331
Comments
What can Hutch do about this? |
I've got this issue, too, and I see that the consumers are registered when the |
I'm not familiar with this Rails autoloader but in general, you have one lazy init code path that's unaware of another lazy init code path. Something (such as eager load) has to kick the tires. In case of Rails, it probably should be driven by Rails and not Hutch? |
I guess so, or the consumers registration could happen differently - I'm not sure what would work best, though. autoloader = Rails.autoloaders.main
Dir.glob(File.join("**", "*_consumer.rb")).each do |consumer|
autoloader.preload(consumer)
end |
Would you be interested in submitting a documentation PR?
…On Thu, Feb 13, 2020 at 11:31 AM Paolo Zaccagnini ***@***.***> wrote:
I guess so, or the consumers registration could happen differently - I'm
not sure what would work best, though.
After some study I've found a better workaround for a Rails 6 app using
the new zeitwerk loader, ie an initializer like this:
autoloader = Rails.autoloaders.main
Dir.glob(File.join("**", "*_consumer.rb")).each do |consumer|
autoloader.preload(consumer)end
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#331>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAAIQXY77UX6UXOXYY4RHLRCUAOXANCNFSM4H4T3AAA>
.
--
MK
Staff Software Engineer, Pivotal/RabbitMQ
|
Will do, and would be glad to have some zeitwerk expert to chime in if there are better ways to tackle this issue |
Here it is, feel free to edit/improve/close: #342 |
That I'm not sure if the |
If you're on Zeitwerk >2.5 and Ruby >=2.7 (I think that's when descendants was introduced?) and have a class that all your consumers descend from, adding this to your hutch.rb initializer seems to work: Rails.autoloaders.main.on_setup do
CustomConsumerClass.descendants.each { |cname| const_get(cname) }
end Although I can't figure out how to get code reloading to work, I need to reboot the hutch process entirely for changes to get picked up (that was true before this change as well). |
I'd happily adopt a PR that focuses on Rails 6+ and retains compatibility with the previous autoloader if, say, the user opts-in by requiring a specific Hutch file. |
Summary
Currently Hutch does not work with Rails 6 (rc1) out-of-the-box since the latter defaults to using Zeitwerk for autoloading paths.
Steps to Reproduce
hutch
as a dependency.<rails_root>/app/consumers/foo_consumer.rb
.bundle exec hutch --autoload-rails
Expected Result
The output should include lines such as these:
Actual Result
The output looks more like this:
Known Workaround
Add the following to
<rails_root>/config/application.rb
:The text was updated successfully, but these errors were encountered: