Skip to content

Commit

Permalink
fix: Don't start the reporter in a Rails console (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlogic authored May 4, 2023
1 parent 0ba8e32 commit c75770e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions judoscale-rails/lib/judoscale/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ class Railtie < ::Rails::Railtie
end

initializer "Judoscale.request_middleware" do |app|
logger.info "Preparing request middleware"
logger.debug "Preparing request middleware"
app.middleware.insert_before Rack::Runtime, RequestMiddleware
end

config.after_initialize do
Reporter.start
# Don't start the reporter in a Rails console.
# NOTE: This is untested because we initialize the Rails test app in test_helper.rb,
# so the reporter has already started before any of the tests run. You can manually
# test this by running `DYNO=web.1 rails c` in sample-apps/rails-sample.
Reporter.start unless defined?(::Rails::Console)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions judoscale-ruby/lib/judoscale/reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def start!(config, adapters)
@pid = Process.pid

if !config.api_base_url
logger.info "Reporter not started: JUDOSCALE_URL is not set"
logger.debug "Reporter not started: JUDOSCALE_URL is not set"
return
end

Expand All @@ -31,7 +31,7 @@ def start!(config, adapters)
metrics_collectors_classes.compact!

if metrics_collectors_classes.empty?
logger.info "Reporter not started: no metrics need to be collected in this process"
logger.debug "Reporter not started: no metrics need to be collected in this process"
return
end

Expand Down

0 comments on commit c75770e

Please sign in to comment.