mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Lets you inject in a RedisConnect into Sidekiq::Client so you can push jobs to different Redis instances in the same application.
This commit is contained in:
parent
b8cbb914f7
commit
5e2b691ac8
4 changed files with 16 additions and 2 deletions
|
@ -66,8 +66,11 @@ module Sidekiq
|
|||
|
||||
def self.redis(&block)
|
||||
raise ArgumentError, "requires a block" if !block
|
||||
redis_connection.with(&block)
|
||||
end
|
||||
|
||||
def self.redis_connection
|
||||
@redis ||= Sidekiq::RedisConnection.create
|
||||
@redis.with(&block)
|
||||
end
|
||||
|
||||
def self.redis=(hash)
|
||||
|
|
|
@ -25,6 +25,10 @@ module Sidekiq
|
|||
@chain
|
||||
end
|
||||
|
||||
def initialize(redis_connection = Sidekiq.redis_connection)
|
||||
@redis_connection = redis_connection
|
||||
end
|
||||
|
||||
##
|
||||
# The main method used to push a job to Redis. Accepts a number of options:
|
||||
#
|
||||
|
@ -135,7 +139,7 @@ module Sidekiq
|
|||
|
||||
def raw_push(payloads)
|
||||
pushed = false
|
||||
Sidekiq.redis do |conn|
|
||||
@redis_connection.with do |conn|
|
||||
if payloads.first['at']
|
||||
pushed = conn.zadd('schedule', payloads.map do |hash|
|
||||
at = hash.delete('at').to_s
|
||||
|
|
|
@ -20,10 +20,12 @@ class TestClient < Sidekiq::Test
|
|||
def @redis.with; yield self; end
|
||||
def @redis.exec; true; end
|
||||
Sidekiq.instance_variable_set(:@redis, @redis)
|
||||
Sidekiq::Client.instance_variable_set(:@default, nil)
|
||||
end
|
||||
|
||||
after do
|
||||
Sidekiq.instance_variable_set(:@redis, REDIS)
|
||||
Sidekiq::Client.instance_variable_set(:@default, nil)
|
||||
end
|
||||
|
||||
it 'raises ArgumentError with invalid params' do
|
||||
|
|
|
@ -4,6 +4,7 @@ require 'sidekiq/scheduled'
|
|||
class TestScheduling < Sidekiq::Test
|
||||
describe 'middleware' do
|
||||
before do
|
||||
Sidekiq::Client.instance_variable_set(:@default, nil)
|
||||
@redis = Minitest::Mock.new
|
||||
# Ugh, this is terrible.
|
||||
Sidekiq.instance_variable_set(:@redis, @redis)
|
||||
|
@ -11,6 +12,10 @@ class TestScheduling < Sidekiq::Test
|
|||
def @redis.with; yield self; end
|
||||
end
|
||||
|
||||
after do
|
||||
Sidekiq::Client.instance_variable_set(:@default, nil)
|
||||
end
|
||||
|
||||
class ScheduledWorker
|
||||
include Sidekiq::Worker
|
||||
sidekiq_options :queue => :custom_queue
|
||||
|
|
Loading…
Reference in a new issue