From 207505e6bdd3b824660db7bab09c5b905bc9ab09 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Mon, 7 Oct 2024 12:05:26 -0300 Subject: [PATCH] Skip starting Judoscale reporter on `rails runner` process Similar to when running the `rails console`, we want to skip the reporter on `rails runner` to prevent it initializing another background thread and triggering an API call to our backend when executing one-off commands via the runner. --- judoscale-rails/lib/judoscale/rails/railtie.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/judoscale-rails/lib/judoscale/rails/railtie.rb b/judoscale-rails/lib/judoscale/rails/railtie.rb index 10d21a45..73ebd6d7 100644 --- a/judoscale-rails/lib/judoscale/rails/railtie.rb +++ b/judoscale-rails/lib/judoscale/rails/railtie.rb @@ -12,9 +12,9 @@ module Rails class Railtie < ::Rails::Railtie include Judoscale::Logger - def in_rails_console? - # This is gross, but we can't find a more reliable way to detect if we're in a Rails console. - caller.any? { |call| call.include?("console_command.rb") } + def in_rails_console_or_runner? + # This is gross, but we can't find a more reliable way to detect if we're in a Rails console/runner. + caller.any? { |call| call.include?("console_command.rb") || call.include?("runner_command.rb") } end def in_rake_task?(task_regex) @@ -36,8 +36,8 @@ def judoscale_config end config.after_initialize do - if in_rails_console? - logger.debug "No reporting since we're in a Rails console" + 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:/) logger.debug "No reporting since we're in a build process" elsif judoscale_config.start_reporter_after_initialize