mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Merge pull request #1315 from barelyknown/push-bulk-returns-jids
#push_bulk returns an array of jids
This commit is contained in:
commit
f787fea2c0
4 changed files with 22 additions and 9 deletions
|
@ -1,3 +1,8 @@
|
|||
2.17.0
|
||||
-----------
|
||||
|
||||
- Change `Sidekiq::Client.push_bulk` to return array of pushed `jid`s.
|
||||
|
||||
2.16.1
|
||||
-----------
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
module Sidekiq
|
||||
VERSION = "2.16.1"
|
||||
VERSION = "2.17.0"
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue