-
-
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.
Close #121 See readme for more information
- Loading branch information
Showing
9 changed files
with
78 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module SidekiqUniqueJobs | ||
module Lock | ||
class UntilAndWhileExecuting < UntilExecuting | ||
def execute(callback) | ||
lock = WhileExecuting.new(item, redis_pool) | ||
lock.synchronize do | ||
callback.call if unlock(:server) | ||
yield | ||
end | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class UntilAndWhileExecuting | ||
include Sidekiq::Worker | ||
|
||
sidekiq_options queue: :working | ||
sidekiq_options unique: :until_and_while_executing | ||
|
||
def perform | ||
end | ||
end |
2 changes: 1 addition & 1 deletion
2
spec/jobs/until_executing_worker.rb → spec/jobs/until_executing_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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class UntilExecutingWorker | ||
class UntilExecutingJob | ||
include Sidekiq::Worker | ||
|
||
sidekiq_options queue: :working | ||
|
36 changes: 36 additions & 0 deletions
36
spec/lib/sidekiq_unique_jobs/lock/until_and_while_executing_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,36 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe SidekiqUniqueJobs::Lock::UntilAndWhileExecuting do | ||
let(:item) do | ||
{ | ||
'jid' => 'maaaahjid', | ||
'queue' => 'dupsallowed', | ||
'class' => 'UntilAndWhileExecuting', | ||
'unique' => 'until_executed', | ||
'args' => [1] | ||
} | ||
end | ||
let(:callback) { -> {} } | ||
subject { described_class.new(item) } | ||
describe '#execute' do | ||
before { subject.lock(:client) } | ||
let(:runtime_lock) { SidekiqUniqueJobs::Lock::WhileExecuting.new(item, nil) } | ||
|
||
it 'unlocks the unique key before yielding' do | ||
expect(SidekiqUniqueJobs::Lock::WhileExecuting).to receive(:new).with(item, nil).and_return(runtime_lock) | ||
expect(callback).to receive(:call) | ||
subject.execute(callback) do | ||
|
||
Sidekiq.redis do |c| | ||
expect(c.keys('uniquejobs:*').size).to eq(1) | ||
end | ||
|
||
10.times { Sidekiq::Client.push(item) } | ||
|
||
Sidekiq.redis do |c| | ||
expect(c.keys('uniquejobs:*').size).to eq(2) | ||
end | ||
end | ||
end | ||
end | ||
end |
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