1
0
Fork 0
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:
Mike Perham 2014-03-26 20:35:57 -07:00
parent 83aea0690e
commit d0d7acaf5e
2 changed files with 30 additions and 1 deletions

View file

@ -34,6 +34,25 @@ module Sidekiq
Sidekiq.logger
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
def perform_async(*args)
@ -81,7 +100,7 @@ module Sidekiq
end
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)
end

View file

@ -247,6 +247,16 @@ class TestClient < Sidekiq::Test
DWorker.perform_async(1,2,3)
conn.verify
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
conn = MiniTest::Mock.new
conn.expect(:zadd, 1, [String, Array])