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

Add unlocked reflect to locksmith unlock! #783

Merged
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
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ Want to show me some ❤️ for the hard work I do on this gem? You can use the
- [reschedule_failed](#reschedule_failed)
- [rescheduled](#rescheduled)
- [timeout](#timeout)
- [unlock_failed](#unlock_failed)
- [unlocked](#unlocked)
- [unknown_sidekiq_worker](#unknown_sidekiq_worker)
- [Show Locks](#show-locks)
- [Show Lock](#show-lock)
- [unlock_failed](#unlock_failed)
- [unlocked](#unlocked)
- [unknown_sidekiq_worker](#unknown_sidekiq_worker)
- [Show Locks](#show-locks)
- [Show Lock](#show-lock)
- [Testing](#testing)
- [Validating Worker Configuration](#validating-worker-configuration)
- [Uniqueness](#uniqueness)
Expand Down Expand Up @@ -545,23 +545,23 @@ For when a job was successfully rescheduled

This is also mostly useful for reporting/metrics purposes. What this reflection does is signal that the job was configured to wait (`lock_timeout` was configured), but we couldn't retrieve a lock even though we waited for some time.

### unlock_failed
#### unlock_failed

This means that the server middleware could not unlock your job and the lock is kept (potentially preventing subsequent jobs from being pushed or processed).

### unlocked
#### unlocked

Also mostly useful for reporting purposes. The job was successfully unlocked.

### unknown_sidekiq_worker
#### unknown_sidekiq_worker

The reason this happens is that the server couldn't find a valid sidekiq worker class. Most likely, that worker isn't intended to be processed by this sidekiq server instance.

#### Show Locks
### Show Locks

![Locks](assets/unique_digests_1.png)

#### Show Lock
### Show Lock

![Lock](assets/unique_digests_2.png)

Expand Down
5 changes: 4 additions & 1 deletion lib/sidekiq_unique_jobs/locksmith.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ def unlock(conn = nil)
#
def unlock!(conn = nil)
call_script(:unlock, key.to_a, argv, conn) do |unlocked_jid|
reflect(:debug, :unlocked, item, unlocked_jid) if unlocked_jid == job_id
if unlocked_jid == job_id
reflect(:debug, :unlocked, item, unlocked_jid)
reflect(:unlocked, item)
end

unlocked_jid
end
Expand Down
12 changes: 6 additions & 6 deletions spec/sidekiq_unique_jobs/locksmith_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,10 @@
# expect(locksmith_two).not_to have_received(:reflect).with(:locked, item_two)
# end

# it "reflects on unlocked" do
# locksmith_one.lock
# allow(locksmith_one).to receive(:reflect)
# locksmith_one.unlock
# expect(locksmith_one).to have_received(:reflect).with(:unlocked, item_one)
# end
it "reflects on unlocked" do
locksmith_one.lock
allow(locksmith_one).to receive(:reflect)
locksmith_one.unlock
expect(locksmith_one).to have_received(:reflect).with(:unlocked, item_one)
end
end