Skip to content

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

Conversation

stympy
Copy link
Member

@stympy stympy commented Jun 5, 2025

Also, ensure the database is connected before loading the SolidQueue plugin.

Fixes #694

Also, ensure the database is connected before loading the SolidQueue plugin.
@stympy stympy requested review from roelbondoc and Copilot June 5, 2025 12:06
@stympy stympy linked an issue Jun 5, 2025 that may be closed by this pull request
Copy link

@Copilot Copilot AI left a 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? }

Comment on lines 5 to 7
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? }
Copy link
Preview

Copilot AI Jun 5, 2025

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.

Suggested change
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.

Comment on lines 4 to 6
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') }
Copy link
Preview

Copilot AI Jun 5, 2025

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.

Suggested change
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.

Copy link
Contributor

@roelbondoc roelbondoc left a 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.

@stympy
Copy link
Member Author

stympy commented Jun 5, 2025

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. :)

Copy link
Contributor

@roelbondoc roelbondoc left a 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.

@stympy stympy merged commit 14ae485 into master Jun 5, 2025
86 checks passed
@stympy stympy deleted the 694-insights-attempts-database-connections-during-asset-precompilation branch June 5, 2025 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Insights attempts database connections during asset precompilation
2 participants