Skip to content

Commit

Permalink
Initialize Sidekiq 6 error_handler
Browse files Browse the repository at this point in the history
the same way its CLI does.
  • Loading branch information
reidmorrison committed Jul 4, 2024
1 parent 34ffd8e commit 9cce078
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/rails_semantic_logger/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class Engine < ::Rails::Engine
end

::Sidekiq.configure_server do |config|
config.logger = ::SemanticLogger[::Sidekiq]
config.logger = ::SemanticLogger[::Sidekiq]
if config.respond_to?(:options)
config.options[:job_logger] = RailsSemanticLogger::Sidekiq::JobLogger
else
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_semantic_logger/sidekiq/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def self.delete_default_error_handler(error_handlers)

return unless defined?(::Sidekiq::ExceptionHandler)
existing = error_handlers.find { |handler| handler.is_a?(::Sidekiq::ExceptionHandler::Logger) }
return config.error_handlers.delete(existing) if existing
return error_handlers.delete(existing) if existing
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/sidekiq_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class SidekiqTest < Minitest::Test
message: "Start #perform",
metric: "sidekiq.queue.latency",
named_tags: {jid: nil, queue: "default"},
exception: :nil
exception: :nil
)
assert messages[0].metric_amount.is_a?(Float)

Expand Down
4 changes: 4 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
ENV["DISABLE_DATABASE_ENVIRONMENT_CHECK"] = "1"
# Load first so Sidekiq thinks it is running as a server instance
require "sidekiq/cli"
if defined?(Sidekiq::DEFAULT_ERROR_HANDLER)
# Set by Sidekiq CLI at startup
Sidekiq.options[:error_handlers] << Sidekiq::DEFAULT_ERROR_HANDLER
end
require_relative "dummy/config/environment"

require "rails/test_help"
Expand Down

0 comments on commit 9cce078

Please sign in to comment.