Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
dmke committed Nov 18, 2024
1 parent 6f688ca commit 7779eb8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
11 changes: 9 additions & 2 deletions lib/mini_scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,23 @@ def self.configure
yield self
end

SidekiqExceptionHandler =
if defined?(Sidekiq.default_configuration) # Sidekiq 7+
->(ex, ctx, _config = nil) { Sidekiq.default_configuration.handle_exception(ex, ctx) }
else # Sidekiq 6.5
->(ex, ctx, _config = nil) { Sidekiq.handle_exception(ex, ctx) }
end

def self.job_exception_handler(&blk)
@job_exception_handler = blk if blk
@job_exception_handler
end

def self.handle_job_exception(ex, context = {})
def self.handle_job_exception(ex, context = {}, _config = nil)
if job_exception_handler
job_exception_handler.call(ex, context)
else
Sidekiq.default_configuration.handle_exception(ex, context)
SidekiqExceptionHandler.call(ex, context)
end
end

Expand Down
18 changes: 14 additions & 4 deletions spec/mini_scheduler/manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -418,17 +418,25 @@ def expect_job_failure(ex, ctx)
class TempSidekiqLogger
attr_accessor :exception, :context

def call(ex, ctx, _component)
def call(ex, ctx, _config = nil)
self.exception = ex
self.context = ctx
end
end

let(:logger) { TempSidekiqLogger.new }

before { Sidekiq.default_configuration.error_handlers << logger }
let(:error_handlers) do
if defined?(Sidekiq.default_configuration)
Sidekiq.default_configuration.error_handlers
else
Sidekiq.error_handlers
end
end

after { Sidekiq.default_configuration.error_handlers.delete(logger) }
before { error_handlers << logger }

after { error_handlers.delete(logger) }

it "captures failed jobs" do
manager.blocking_tick
Expand All @@ -438,7 +446,9 @@ def call(ex, ctx, _component)
end

context "with custom handler" do
before { MiniScheduler.job_exception_handler { |ex, ctx| expect_job_failure(ex, ctx) } }
before do
MiniScheduler.job_exception_handler { |ex, ctx, _config = nil| expect_job_failure(ex, ctx) }
end

after { MiniScheduler.instance_variable_set :@job_exception_handler, nil }

Expand Down

0 comments on commit 7779eb8

Please sign in to comment.