Comments (10)
Subscribers, including LogSubscribers, like most other registries in the Rails frameworks, are not expected to handle reloads.
Now that lib
can be autoloaded, makes this situation difficult. Either we change most of those registries to be reload aware, perhaps making them less performant or we document what can't be reloaded, which is probably everything that was made to be used in libraries, like the mentioned feature.
from rails.
Stuff that is cached cannot be reloadable. Middleware is an example, this section of the autoloading guide explains this (but I see there is an obsolete mention to lib
).
If you still want lib
to be reloadable, one way to organize this would be to create lib/log_subscribers
and ignore that subdirectory in the autoload_lib
call.
from rails.
@josegomezr where in the application is the log subscriber loaded?
from rails.
I had something like this:
module Namespace
extend ActiveSupport::Autoload
autoload :MyService
end
and in the soruce of namespace/my_service.rb
.
require_relative ./log_subscriber.rb
Then I saw the repeating messages and blamed the #attach_to
, and with the
results of this research I ended up with:
module Namespace
extend ActiveSupport::Autoload
autoload :MyService # this is the class emitting `xxx.namespace` events.
eager_autoload do
autoload :LogSubscriber
end
# LogSubscriber.attach_to :namespace
LogSubscriber.reaload_capable_attach_to :namespace
end
from rails.
And namespace/my_service.rb
, where was it stored? How was Namespace
loaded?
Subscribers are typically defined while the application boots, because you want them to be ready, when is yours effectively defined?
Are any of those files in the autoload paths?
from rails.
Are any of those files in the autoload paths?
I believe that's the case. Files are in rails-root/lib/
, and application.rb
has:
config.autoload_lib(ignore: %w[tasks])
from rails.
But, who loads these files, and when? Is loading them triggered from config/initializers?
from rails.
I triggered the behavior from the console by:
Namespace::MyService.new().call()
That should be Zeitwerk loading them (?). I didn't do any require
call other than what application.rb
already had.
The way I was intending to use the service [and in turn the subscriber] was in a rake task like:
namespace :ns do
task import_all: :environment do
Namespace::MyService.new().call()
end
end
and just bin/rake ns:import_all
p.s: This is a bit far away from my ruby understanding, I apologize if I can't answer clearly 😅
from rails.
No prob at all :D, I believe I have an idea of your setup now.
About to fly to RailsConf right now, I'll followup if there's anything else worth sharing. Thank you!
from rails.
Stuff that is cached cannot be reloadable. Middleware is an example, this section of the autoloading guide explains this (but I see there is an obsolete mention to lib).
I revised that obsolete paragraph in dcbd6b0. That patch has been backported to 7-1-stable
too.
from rails.
Related Issues (20)
- Possible race condition in postgresql type_map initialization
- rspec tests won't after upgrading from rails 7.1.2 to 7.1.3.2: can't modify frozen Array when requiring environment file HOT 2
- form_with reverting to HTML processing only HOT 5
- Inaccurate docs/comments about ActiveStorage video previewer defaults could be improved HOT 4
- Inconsistent model state when dumped and loaded with Marshal version 7.1 HOT 4
- ActiveRecord connection is checked out/retained despite setting `config.active_record.permanent_connection_checkout = :disallowed` HOT 4
- Default Active Support Logger in Addition to Custom Logger in Rails 7.1 x BroadcastLogger Class in Development environment HOT 1
- Aws::Rails::SqsActiveJob#execute captures StandardError which is too wide HOT 1
- AppGeneratorTest fails because `Could not find gem 'kamal' in locally installed gems.` HOT 1
- `has_one :through` associations ignore preloaded records
- loading credentials key HOT 5
- Different timestamps behaviour with InsertAll HOT 3
- Activerecord: Insert fails on composed_primary_key model with id as not null Identity column
- procfile causes failure on Rails 8.0 HOT 8
- Rails 7.1 changes established database connection after calling `rails db:test:prepare` for multi-database apps HOT 4
- Storage folder seems like it is sometimes not needed
- Storage folder sometimes doesn't need Kamal configuration in Rails 8.0.0.alpha HOT 1
- Content-Type parsing breaks on valid test cases HOT 4
- PostgreSQL Apache AGE Rails (GraphDB driver questions / problems) HOT 6
- s
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rails.