-
Notifications
You must be signed in to change notification settings - Fork 148
fix: avoid database connections during asset precompilation #695
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
fix: avoid database connections during asset precompilation #695
Conversation
Also, ensure the database is connected before loading the SolidQueue plugin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates the SolidQueue plugin registration to skip activation during asset precompilation and ensure the database connection is established before loading the plugin.
- Skip loading plugin when running
assets:precompile
- Require an active database connection before loading SolidQueue
Comments suppressed due to low confidence (1)
lib/honeybadger/plugins/solid_queue.rb:7
- Add tests to cover the new plugin-loading conditions (e.g., during asset precompilation and with no database connection) to prevent regressions.
requirement { defined?(ActiveRecord::Base) && ActiveRecord::Base.connected? }
requirement { config.load_plugin_insights?(:solid_queue) && defined?(::SolidQueue) } | ||
requirement { !defined?(Rake) || !Rake.application.top_level_tasks.include?('assets:precompile') } | ||
requirement { defined?(ActiveRecord::Base) && ActiveRecord::Base.connected? } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider consolidating multiple requirement
calls into a single block combining all conditions for clarity and to ensure they are evaluated together.
requirement { config.load_plugin_insights?(:solid_queue) && defined?(::SolidQueue) } | |
requirement { !defined?(Rake) || !Rake.application.top_level_tasks.include?('assets:precompile') } | |
requirement { defined?(ActiveRecord::Base) && ActiveRecord::Base.connected? } | |
requirement do | |
config.load_plugin_insights?(:solid_queue) && | |
defined?(::SolidQueue) && | |
(!defined?(Rake) || !Rake.application.top_level_tasks.include?('assets:precompile')) && | |
defined?(ActiveRecord::Base) && ActiveRecord::Base.connected? | |
end |
Copilot uses AI. Check for mistakes.
Plugin.register :solid_queue do | ||
requirement { config.load_plugin_insights?(:solid_queue) && defined?(::SolidQueue) } | ||
requirement { !defined?(Rake) || !Rake.application.top_level_tasks.include?('assets:precompile') } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Extract the 'assets:precompile'
string into a named constant or configuration to avoid magic strings and make future updates easier.
Plugin.register :solid_queue do | |
requirement { config.load_plugin_insights?(:solid_queue) && defined?(::SolidQueue) } | |
requirement { !defined?(Rake) || !Rake.application.top_level_tasks.include?('assets:precompile') } | |
ASSETS_PRECOMPILE_TASK = 'assets:precompile' | |
Plugin.register :solid_queue do | |
requirement { config.load_plugin_insights?(:solid_queue) && defined?(::SolidQueue) } | |
requirement { !defined?(Rake) || !Rake.application.top_level_tasks.include?(ASSETS_PRECOMPILE_TASK) } |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. I was thinking about this last night and was thinking of adding this same check to lib/honeybadger/init/rails.rb
and just disabling Insights entirely for that rake task.
That seems like a good idea to me. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated this, and I also moved a the stats collection call until after the config check.
Also, ensure the database is connected before loading the SolidQueue plugin.
Fixes #694