From ed6c30aa88e7b0bc17c38035fcbb753f102fb833 Mon Sep 17 00:00:00 2001 From: Adam McCrea Date: Wed, 16 Oct 2024 10:55:07 -0400 Subject: [PATCH] fix: Allow customizing the rake task regex to avoid starting the reporter (#220) --- judoscale-rails/lib/judoscale/rails/config.rb | 3 ++- judoscale-rails/lib/judoscale/rails/railtie.rb | 2 +- judoscale-rails/test/config_test.rb | 4 ++++ sample-apps/rails-sample/config/initializers/judoscale.rb | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/judoscale-rails/lib/judoscale/rails/config.rb b/judoscale-rails/lib/judoscale/rails/config.rb index 3f55e7fb..a54297ed 100644 --- a/judoscale-rails/lib/judoscale/rails/config.rb +++ b/judoscale-rails/lib/judoscale/rails/config.rb @@ -3,11 +3,12 @@ module Judoscale module Rails module Config - attr_accessor :start_reporter_after_initialize + attr_accessor :start_reporter_after_initialize, :rake_task_ignore_regex def reset super @start_reporter_after_initialize = true + @rake_task_ignore_regex = /assets:|db:/ end end diff --git a/judoscale-rails/lib/judoscale/rails/railtie.rb b/judoscale-rails/lib/judoscale/rails/railtie.rb index 73ebd6d7..244008c9 100644 --- a/judoscale-rails/lib/judoscale/rails/railtie.rb +++ b/judoscale-rails/lib/judoscale/rails/railtie.rb @@ -38,7 +38,7 @@ def judoscale_config config.after_initialize do if in_rails_console_or_runner? logger.debug "No reporting since we're in a Rails console or runner process" - elsif in_rake_task?(/assets:|db:/) + elsif in_rake_task?(judoscale_config.rake_task_ignore_regex) logger.debug "No reporting since we're in a build process" elsif judoscale_config.start_reporter_after_initialize Reporter.start diff --git a/judoscale-rails/test/config_test.rb b/judoscale-rails/test/config_test.rb index ab46c139..759aaa3c 100644 --- a/judoscale-rails/test/config_test.rb +++ b/judoscale-rails/test/config_test.rb @@ -8,5 +8,9 @@ module Judoscale it "adds the start_reporter_after_initialize config option" do _(::Judoscale::Config.instance.start_reporter_after_initialize).must_equal true end + + it "adds the rake_task_ignore_regex config option" do + _(::Judoscale::Config.instance.rake_task_ignore_regex).must_equal(/assets:|db:/) + end end end diff --git a/sample-apps/rails-sample/config/initializers/judoscale.rb b/sample-apps/rails-sample/config/initializers/judoscale.rb index 7a1ab4a0..ef4dec87 100644 --- a/sample-apps/rails-sample/config/initializers/judoscale.rb +++ b/sample-apps/rails-sample/config/initializers/judoscale.rb @@ -3,5 +3,6 @@ Judoscale.configure do |config| # Open https://judoscale-adapter-mock.requestcatcher.com in a browser to monitor requests config.api_base_url = ENV["JUDOSCALE_URL"] || "https://judoscale-adapter-mock.requestcatcher.com" + config.rake_task_ignore_regex = /assets:|db:|middleware/ # config.start_reporter_after_initialize = false end