Skip to content

Commit

Permalink
feat: disable all workers in rails console (#636)
Browse files Browse the repository at this point in the history
As it turns out, the `console` callback is called after `after_initialize`
config callback in the Railtie. This can still cause the metric worker to
startup when it's not meant to. This change will shutdown the
`MetricsWorker` and `EventWorker` when the Rails console is loaded.
  • Loading branch information
roelbondoc authored Nov 14, 2024
1 parent 9731bbf commit d0bcb42
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/honeybadger/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,16 @@ def stop(force = false)
true
end

# Stops the Honeybadger Insights related services.
#
# @example
# Honeybadger.stop_insights # => nil
def stop_insights(force = false)
events_worker&.shutdown(force)
metrics_worker&.shutdown(force)
true
end

# Sends event to events backend
#
# @example
Expand Down
5 changes: 4 additions & 1 deletion lib/honeybadger/init/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ class Railtie < ::Rails::Railtie
end

console do
Honeybadger::Agent.instance.config[:'insights.enabled'] = Honeybadger::Agent.instance.config[:'insights.console.enabled']
unless Honeybadger::Agent.instance.config[:'insights.enabled'] = Honeybadger::Agent.instance.config[:'insights.console.enabled']
Honeybadger::Agent.instance.config.logger.debug("Rails console detected, shutting down Honeybadger Insights workers.")
Honeybadger::Agent.instance.stop_insights
end
end
end
end
Expand Down

0 comments on commit d0bcb42

Please sign in to comment.