-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
164 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Sidekiq | ||
module Lock | ||
class Container | ||
THREAD_KEY = :sidekiq_lock | ||
|
||
def fetch | ||
Thread.current[THREAD_KEY] | ||
end | ||
|
||
def store(lock) | ||
Thread.current[THREAD_KEY] = lock | ||
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
def set_sidekiq_lock(worker_class, payload) | ||
options = worker_class.get_sidekiq_options['lock'] | ||
Thread.current[Sidekiq::Lock::THREAD_KEY] = Sidekiq::Lock::RedisLock.new(options, payload) | ||
Sidekiq.lock_container.store(Sidekiq::Lock::RedisLock.new(options, payload)) | ||
end | ||
|
||
def clear_sidekiq_lock | ||
Thread.current[Sidekiq::Lock::THREAD_KEY] = nil | ||
Sidekiq.lock_container.store(nil) | ||
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,23 @@ | ||
require 'test_helper' | ||
require 'open3' | ||
|
||
module Sidekiq | ||
module Lock | ||
describe Container do | ||
it 'stores and fetches given value under Thread.current' do | ||
begin | ||
container = Sidekiq::Lock::Container.new | ||
thread_key = Sidekiq::Lock::Container::THREAD_KEY | ||
|
||
Thread.current[thread_key] = 'value' | ||
assert_equal 'value', container.fetch | ||
|
||
container.store 'new-value' | ||
assert_equal Thread.current[thread_key], 'new-value' | ||
ensure | ||
Thread.current[thread_key] = nil | ||
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
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