Skip to content

Commit

Permalink
Handle strategy fallbacks properly (#809)
Browse files Browse the repository at this point in the history
  • Loading branch information
matejrisek committed Nov 10, 2023
1 parent e430e39 commit f8ade43
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/sidekiq_unique_jobs/lock_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,20 @@ def errors_as_string

# the strategy to use as conflict resolution from sidekiq client
def on_client_conflict
@on_client_conflict ||= on_conflict["client"] || on_conflict[:client] if on_conflict.is_a?(Hash)
@on_client_conflict ||= on_conflict
if on_conflict.is_a?(Hash)
@on_client_conflict ||= on_conflict["client"] || on_conflict[:client]
else
@on_client_conflict ||= on_conflict
end
end

# the strategy to use as conflict resolution from sidekiq server
def on_server_conflict
@on_server_conflict ||= on_conflict["server"] || on_conflict[:server] if on_conflict.is_a?(Hash)
@on_server_conflict ||= on_conflict
if on_conflict.is_a?(Hash)
@on_server_conflict ||= on_conflict["server"] || on_conflict[:server]
else
@on_server_conflict ||= on_conflict
end
end
end
end
12 changes: 12 additions & 0 deletions spec/sidekiq_unique_jobs/lock_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@

it { is_expected.to eq(:replace) }
end

context "when on_conflict is defined only for server" do
let(:on_conflict) { {server: :log}}

it { is_expected.to be_nil }
end
end

describe "#on_server_conflict" do
Expand All @@ -158,5 +164,11 @@

it { is_expected.to eq(:reschedule) }
end

context "when on_conflict is defined only for client" do
let(:on_conflict) { {client: :log}}

it { is_expected.to be_nil }
end
end
end

0 comments on commit f8ade43

Please sign in to comment.