1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Merge pull request #295 from AutoUncle/master

Added another Resque compatibility helper #enqueue_to
This commit is contained in:
Mike Perham 2012-09-07 08:30:40 -07:00
commit a270fd8dc1
3 changed files with 35 additions and 2 deletions

View file

@ -65,14 +65,22 @@ module Sidekiq
pushed ? item['jid'] : nil
end
# Redis compatibility helper. Example usage:
# Resque compatibility helpers.
#
# Sidekiq::Client.enqueue(MyWorker, 'foo', 1, :bat => 'bar')
# Example usage:
# Sidekiq::Client.enqueue(MyWorker, 'foo', 1, :bat => 'bar')
#
# Messages are enqueued to the 'default' queue.
#
def self.enqueue(klass, *args)
klass.perform_async(*args)
end
# Example usage:
# Sidekiq::Client.enqueue_to(:queue_name, MyWorker, 'foo', 1, :bat => 'bar')
#
def self.enqueue_to(queue, klass, *args)
klass.perform_in_queue(queue, *args)
end
end
end

View file

@ -35,6 +35,10 @@ module Sidekiq
client_push('class' => self, 'args' => args)
end
def perform_in_queue(queue, *args)
client_push('queue' => queue, 'class' => self, 'args' => args)
end
def perform_in(interval, *args)
int = interval.to_f
ts = (int < 1_000_000_000 ? Time.now.to_f + int : int)

View file

@ -69,6 +69,27 @@ class TestClient < MiniTest::Unit::TestCase
@redis.verify
end
it 'handles perform_in_queue' do
@redis.expect :rpush, 1, ['queue:custom_queue', String]
pushed = MyWorker.perform_in_queue(:custom_queue, 1, 2)
assert pushed
@redis.verify
end
it 'handles perform_in_queue on failure' do
@redis.expect :rpush, nil, ['queue:custom_queue', String]
pushed = MyWorker.perform_in_queue(:custom_queue, 1, 2)
refute pushed
@redis.verify
end
it 'enqueues messages to redis' do
@redis.expect :rpush, 1, ['queue:custom_queue', String]
pushed = Sidekiq::Client.enqueue_to(:custom_queue, MyWorker, 1, 2)
assert pushed
@redis.verify
end
class QueuedWorker
include Sidekiq::Worker
sidekiq_options :queue => :flimflam, :timeout => 1