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 195cec6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 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) { 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
6 changes: 4 additions & 2 deletions spec/mini_scheduler/manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def expect_job_failure(ex, ctx)
class TempSidekiqLogger
attr_accessor :exception, :context

def call(ex, ctx, _component)
def call(ex, ctx, _config)
self.exception = ex
self.context = ctx
end
Expand All @@ -438,7 +438,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 195cec6

Please sign in to comment.