mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Inline testing now runs through client middleware before executing, fixes #465
This commit is contained in:
parent
ae1ff3358a
commit
576eb6fa56
3 changed files with 22 additions and 16 deletions
|
@ -40,16 +40,7 @@ module Sidekiq
|
|||
normed, payload = process_single(item['class'], normed)
|
||||
|
||||
pushed = false
|
||||
Sidekiq.redis do |conn|
|
||||
if normed['at']
|
||||
pushed = conn.zadd('schedule', normed['at'].to_s, payload)
|
||||
else
|
||||
_, pushed = conn.multi do
|
||||
conn.sadd('queues', normed['queue'])
|
||||
conn.rpush("queue:#{normed['queue']}", payload)
|
||||
end
|
||||
end
|
||||
end if normed
|
||||
pushed = raw_push(normed, payload) if normed
|
||||
pushed ? normed['jid'] : nil
|
||||
end
|
||||
|
||||
|
@ -104,6 +95,21 @@ module Sidekiq
|
|||
|
||||
private
|
||||
|
||||
def self.raw_push(normed, payload) # :nodoc:
|
||||
pushed = false
|
||||
Sidekiq.redis do |conn|
|
||||
if normed['at']
|
||||
pushed = conn.zadd('schedule', normed['at'].to_s, payload)
|
||||
else
|
||||
_, pushed = conn.multi do
|
||||
conn.sadd('queues', normed['queue'])
|
||||
conn.rpush("queue:#{normed['queue']}", payload)
|
||||
end
|
||||
end
|
||||
end
|
||||
pushed
|
||||
end
|
||||
|
||||
def self.process_single(worker_class, item)
|
||||
queue = item['queue']
|
||||
|
||||
|
|
|
@ -27,9 +27,9 @@ module Sidekiq
|
|||
# assert_equal 1, $external_variable
|
||||
#
|
||||
singleton_class.class_eval do
|
||||
alias_method :push_old, :push
|
||||
def push(hash)
|
||||
hash['class'].new.perform(*Sidekiq.load_json(Sidekiq.dump_json(hash['args'])))
|
||||
alias_method :raw_push_old, :raw_push
|
||||
def raw_push(hash, _)
|
||||
hash['class'].constantize.new.perform(*Sidekiq.load_json(Sidekiq.dump_json(hash['args'])))
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -46,9 +46,9 @@ class TestInline < MiniTest::Unit::TestCase
|
|||
|
||||
after do
|
||||
Sidekiq::Client.singleton_class.class_eval do
|
||||
remove_method :push
|
||||
alias_method :push, :push_old
|
||||
remove_method :push_old
|
||||
remove_method :raw_push
|
||||
alias_method :raw_push, :raw_push_old
|
||||
remove_method :raw_push_old
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue