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

#push_bulk returns an array of jids

This commit is contained in:
barelyknown 2013-11-05 11:17:30 -06:00
parent 7c22a1deb5
commit 97d2f28f3a
2 changed files with 16 additions and 8 deletions

View file

@ -53,7 +53,8 @@ module Sidekiq
##
# Push a large number of jobs to Redis. In practice this method is only
# useful if you are pushing tens of thousands of jobs or more. This method
# useful if you are pushing tens of thousands of jobs or more, or if you need
# to ensure that a batch doesn't complete prematurely. This method
# basically cuts down on the redis round trip latency.
#
# Takes the same arguments as #push except that args is expected to be
@ -61,7 +62,7 @@ module Sidekiq
# is run through the client middleware pipeline and each job gets its own Job ID
# as normal.
#
# Returns the number of jobs pushed or nil if the pushed failed. The number of jobs
# Returns an array of the of pushed jobs' jids or nil if the pushed failed. The number of jobs
# pushed can be less than the number given if the middleware stopped processing for one
# or more jobs.
def push_bulk(items)
@ -73,7 +74,7 @@ module Sidekiq
pushed = false
pushed = raw_push(payloads) if !payloads.empty?
pushed ? payloads.size : nil
pushed ? payloads.collect { |payload| payload['jid'] } : nil
end
class << self

View file

@ -168,12 +168,17 @@ class TestClient < Sidekiq::Test
Sidekiq::Queue.new.clear
end
it 'can push a large set of jobs at once' do
count = Sidekiq::Client.push_bulk('class' => QueuedWorker, 'args' => (1..1_000).to_a.map { |x| Array(x) })
assert_equal 1_000, count
jids = Sidekiq::Client.push_bulk('class' => QueuedWorker, 'args' => (1..1_000).to_a.map { |x| Array(x) })
assert_equal 1_000, jids.size
end
it 'can push a large set of jobs at once using a String class' do
count = Sidekiq::Client.push_bulk('class' => 'QueuedWorker', 'args' => (1..1_000).to_a.map { |x| Array(x) })
assert_equal 1_000, count
jids = Sidekiq::Client.push_bulk('class' => 'QueuedWorker', 'args' => (1..1_000).to_a.map { |x| Array(x) })
assert_equal 1_000, jids.size
end
it 'returns the jids for the jobs' do
Sidekiq::Client.push_bulk('class' => 'QueuedWorker', 'args' => (1..2).to_a.map { |x| Array(x) }).each do |jid|
assert_match /[0-9a-f]{12}/, jid
end
end
end
@ -203,7 +208,9 @@ class TestClient < Sidekiq::Test
begin
assert_equal nil, Sidekiq::Client.push('class' => MyWorker, 'args' => [0])
assert_match /[0-9a-f]{12}/, Sidekiq::Client.push('class' => MyWorker, 'args' => [1])
assert_equal 1, Sidekiq::Client.push_bulk('class' => MyWorker, 'args' => [[0], [1]])
Sidekiq::Client.push_bulk('class' => MyWorker, 'args' => [[0], [1]]).each do |jid|
assert_match /[0-9a-f]{12}/, jid
end
ensure
Sidekiq.client_middleware.remove Stopper
end