-
-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This fixes the exception posted below when using `on_conflict: replace` and potentially other bugs related to `on_conflict`. Before [this change][1] `BasicLock.lock` always returned either the acquired lock or the return value of `call_strategy`. Since `Middleware::Client#lock` now only yields when `lock_instance.lock` yields we have to also `yield` inside the lock instances when the lock was acquired via `lock_failed` (i.e. a `on_conflict` strategy). ``` NoMethodError: undefined method `key?' for "f5d69f8fd2e1f3dde8cee02e":String from sidekiq/client.rb:197:in `atomic_push' from sidekiq/client.rb:190:in `block (2 levels) in raw_push' from redis.rb:2489:in `block in multi' from redis.rb:69:in `block in synchronize' from monitor.rb:202:in `synchronize' from monitor.rb:202:in `mon_synchronize' from redis.rb:69:in `synchronize' from redis.rb:2483:in `multi' from sidekiq/client.rb:189:in `block in raw_push' from connection_pool.rb:63:in `block (2 levels) in with' from connection_pool.rb:62:in `handle_interrupt' from connection_pool.rb:62:in `block in with' from connection_pool.rb:59:in `handle_interrupt' from connection_pool.rb:59:in `with' from sidekiq/client.rb:188:in `raw_push' from sidekiq/client.rb:74:in `push' from sidekiq/worker.rb:240:in `client_push' from sidekiq/worker.rb:215:in `perform_in' ``` #590 [1]: s://github.com/mhenrixon/sidekiq-unique-jobs/commit/8c8d54c8b9dea363a7d8b8aeaceb2e82966b8503
- Loading branch information
Showing
6 changed files
with
55 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
spec/support/workers/until_and_while_executing_replace_job.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
# :nocov: | ||
|
||
class UntilAndWhileExecutingReplaceJob | ||
include Sidekiq::Worker | ||
|
||
sidekiq_options lock: :until_and_while_executing, | ||
queue: :working, | ||
on_conflict: :replace | ||
|
||
def self.lock_args(args) | ||
[args[0]] | ||
end | ||
|
||
def perform(key); end | ||
end |
30 changes: 30 additions & 0 deletions
30
spec/workers/until_and_while_executing_replace_job_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe UntilAndWhileExecutingReplaceJob do | ||
it_behaves_like "sidekiq with options" do | ||
let(:options) do | ||
{ | ||
"queue" => :working, | ||
"retry" => true, | ||
"lock" => :until_and_while_executing, | ||
"on_conflict" => :replace, | ||
} | ||
end | ||
end | ||
|
||
it "replaces the previous job successfully" do | ||
Sidekiq::Testing.disable! do | ||
set = Sidekiq::ScheduledSet.new | ||
|
||
described_class.perform_at(Time.now + 30, "unique", "first argument") | ||
expect(set.size).to eq(1) | ||
expect(set.first.item["args"]).to eq(["unique", "first argument"]) | ||
|
||
described_class.perform_at(Time.now + 30, "unique", "new argument") | ||
expect(set.size).to eq(1) | ||
expect(set.first.item["args"]).to eq(["unique", "new argument"]) | ||
|
||
set.each(&:delete) | ||
end | ||
end | ||
end |