Skip to content

Commit

Permalink
Skip starting Judoscale reporter on rails runner process
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
carlosantoniodasilva committed Oct 7, 2024
1 parent bf92a59 commit 207505e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions judoscale-rails/lib/judoscale/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 207505e

Please sign in to comment.