Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stringify on_conflict hash in Job prepare method #507

Merged
merged 1 commit into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/sidekiq_unique_jobs/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module Job
# Adds timeout, expiration, lock_args, lock_prefix and lock_digest to the sidekiq job hash
# @return [Hash] the job hash
def prepare(item)
stringify_on_conflict_hash(item)
add_lock_timeout(item)
add_lock_ttl(item)
add_digest(item)
Expand All @@ -27,6 +28,13 @@ def add_digest(item)

private

def stringify_on_conflict_hash(item)
on_conflict = item[ON_CONFLICT]
return unless on_conflict.is_a?(Hash)

item[ON_CONFLICT] = on_conflict.deep_stringify_keys
end

def add_lock_ttl(item)
item[LOCK_TTL] = SidekiqUniqueJobs::LockTTL.calculate(item)
end
Expand Down
17 changes: 17 additions & 0 deletions spec/sidekiq_unique_jobs/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,22 @@
},
)
end

context "when there is a hash in on_conflict" do
let(:worker_class) { UniqueJobOnConflictHash }

let(:job) { worker_class.get_sidekiq_options }

it "stringifies the on_conflict hash" do
expect(prepare).to match(
hash_including(
"on_conflict" => {
"client" => :log,
"server" => :reschedule,
},
),
)
end
end
end
end
6 changes: 3 additions & 3 deletions spec/sidekiq_unique_jobs/sidekiq_worker_methods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ def initialize(worker_class)
let(:worker_class) { UniqueJobOnConflictHash }

it do
expect(worker_options).to eq(
{
expect(worker_options).to match(
hash_including(
"lock" => :until_and_while_executing,
"on_conflict" => {
"client" => :log,
"server" => :reschedule,
},
"queue" => :customqueue,
"retry" => true,
},
),
)
end
end
Expand Down