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

Fix(unlock): Delete primed keys on last entry #726

Merged
merged 3 commits into from
Jul 28, 2022
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
5 changes: 5 additions & 0 deletions lib/sidekiq_unique_jobs/lua/unlock.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ if locked_count and locked_count < 1 then
redis.call(del_cmd, locked)
end

if redis.call("LLEN", primed) == 0 then
log_debug(del_cmd, primed)
redis.call(del_cmd, primed)
end

if limit and limit <= 1 and locked_count and locked_count <= 1 then
log_debug("ZREM", digests, digest)
redis.call("ZREM", digests, digest)
Expand Down
18 changes: 14 additions & 4 deletions spec/sidekiq_unique_jobs/lua/unlock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,36 @@
end

shared_examples "unlock with ttl" do
it { expect { unlock }.to change { zcard(key.changelog) }.by(1) }
it { expect { unlock }.to change { ttl(key.digest) }.to(-2) }
it { expect { unlock }.to change { unique_keys }.to(%w[uniquejobs:digest:QUEUED]) }
it { expect { unlock }.to change { llen(key.queued) }.by(1) }

it { expect { unlock }.to change { llen(key.primed) }.by(0) }

it { expect { unlock }.to change { ttl(key.locked) }.to(-2) }
it { expect { unlock }.to change { hget(key.locked, job_id_one) }.to(nil) }

it { expect { unlock }.to change { ttl(key.digest) }.to(-2) }
it { expect { unlock }.to change { zcard(key.digests) }.by(-1) }
it { expect { unlock }.to change { digests.entries }.from(key.digest => kind_of(Float)).to({}) }

it { expect { unlock }.to change { zcard(key.changelog) }.by(1) }
end

shared_examples "unlock without ttl" do
it { expect { unlock }.to change { zcard(key.changelog) }.by(1) }
it { expect { unlock }.to change { ttl(key.digest) }.from(-1).to(-2) }
it { expect { unlock }.to change { unique_keys }.to(%w[uniquejobs:digest:QUEUED]) }
it { expect { unlock }.to change { lrange(key.queued, -1, 0) }.to(["1"]) }
it { expect { unlock }.to change { llen(key.queued) }.by(1) }

it { expect { unlock }.to change { llen(key.primed) }.by(0) }

it { expect { unlock }.to change { ttl(key.locked) }.to(-2) }
it { expect { unlock }.to change { hget(key.locked, job_id_one) }.to(nil) }

it { expect { unlock }.to change { ttl(key.digest) }.from(-1).to(-2) }
it { expect { unlock }.to change { zcard(key.digests) }.by(-1) }
it { expect { unlock }.to change { digests.entries }.from(key.digest => kind_of(Float)).to({}) }

it { expect { unlock }.to change { zcard(key.changelog) }.by(1) }
end

context "with lock: :until_expired", :with_a_lock do
Expand Down