mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Revert "Remove .via, not sure it's necessary."
This reverts commit dd798bb6be
.
This commit is contained in:
parent
83aea0690e
commit
d0d7acaf5e
2 changed files with 30 additions and 1 deletions
|
@ -34,6 +34,25 @@ module Sidekiq
|
||||||
Sidekiq.logger
|
Sidekiq.logger
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Allows sharding of jobs across any number of Redis instances. All jobs
|
||||||
|
# defined within the block will use the given Redis connection pool.
|
||||||
|
#
|
||||||
|
# pool = ConnectionPool.new { Redis.new }
|
||||||
|
# Sidekiq::Worker.via(pool) do
|
||||||
|
# SomeWorker.perform_async(1,2,3)
|
||||||
|
# SomeOtherWorker.perform_async(1,2,3)
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# Generally this is only needed for very large Sidekiq installs processing
|
||||||
|
# more than thousands jobs per second.
|
||||||
|
def self.via(pool)
|
||||||
|
raise ArgumentError, "No pool given" if pool.nil?
|
||||||
|
Thread.current[:sidekiq_via_pool] = pool
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
Thread.current[:sidekiq_via_pool] = nil
|
||||||
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
|
|
||||||
def perform_async(*args)
|
def perform_async(*args)
|
||||||
|
@ -81,7 +100,7 @@ module Sidekiq
|
||||||
end
|
end
|
||||||
|
|
||||||
def client_push(item) # :nodoc:
|
def client_push(item) # :nodoc:
|
||||||
pool = get_sidekiq_options['pool'] || Sidekiq.redis_pool
|
pool = Thread.current[:sidekiq_via_pool] || get_sidekiq_options['pool'] || Sidekiq.redis_pool
|
||||||
Sidekiq::Client.new(pool).push(item.stringify_keys)
|
Sidekiq::Client.new(pool).push(item.stringify_keys)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -247,6 +247,16 @@ class TestClient < Sidekiq::Test
|
||||||
DWorker.perform_async(1,2,3)
|
DWorker.perform_async(1,2,3)
|
||||||
conn.verify
|
conn.verify
|
||||||
end
|
end
|
||||||
|
it 'allows #via to point to different Redi' do
|
||||||
|
conn = MiniTest::Mock.new
|
||||||
|
conn.expect(:multi, [0, 1])
|
||||||
|
default = Sidekiq::Client.redis_pool
|
||||||
|
Sidekiq::Client.via(ConnectionPool.new(size: 1) { conn }) do
|
||||||
|
CWorker.perform_async(1,2,3)
|
||||||
|
end
|
||||||
|
assert_equal default, Sidekiq::Client.redis_pool
|
||||||
|
conn.verify
|
||||||
|
end
|
||||||
it 'allows Resque helpers to point to different Redi' do
|
it 'allows Resque helpers to point to different Redi' do
|
||||||
conn = MiniTest::Mock.new
|
conn = MiniTest::Mock.new
|
||||||
conn.expect(:zadd, 1, [String, Array])
|
conn.expect(:zadd, 1, [String, Array])
|
||||||
|
|
Loading…
Add table
Reference in a new issue