From 97d2f28f3a3d5c2febfeb61a0d3602d523751c8a Mon Sep 17 00:00:00 2001 From: barelyknown Date: Tue, 5 Nov 2013 11:17:30 -0600 Subject: [PATCH 1/3] #push_bulk returns an array of jids --- lib/sidekiq/client.rb | 7 ++++--- test/test_client.rb | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/sidekiq/client.rb b/lib/sidekiq/client.rb index 9035d8d8..046ba16f 100644 --- a/lib/sidekiq/client.rb +++ b/lib/sidekiq/client.rb @@ -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 diff --git a/test/test_client.rb b/test/test_client.rb index ac2c379f..b2f87c75 100644 --- a/test/test_client.rb +++ b/test/test_client.rb @@ -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 From 8422376205fd0c104af95e9c32dcae96ab9f7c6b Mon Sep 17 00:00:00 2001 From: barelyknown Date: Tue, 5 Nov 2013 11:29:07 -0600 Subject: [PATCH 2/3] bump version to 2.17.0 --- lib/sidekiq/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sidekiq/version.rb b/lib/sidekiq/version.rb index c29cbea0..c692f82e 100644 --- a/lib/sidekiq/version.rb +++ b/lib/sidekiq/version.rb @@ -1,3 +1,3 @@ module Sidekiq - VERSION = "2.16.1" + VERSION = "2.17.0" end From e8a82b28b3036b9ccfb758445db6625e6b777535 Mon Sep 17 00:00:00 2001 From: barelyknown Date: Tue, 5 Nov 2013 11:29:26 -0600 Subject: [PATCH 3/3] update changelog with push_bulk return value change --- Changes.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Changes.md b/Changes.md index dee1e267..73b8a2fe 100644 --- a/Changes.md +++ b/Changes.md @@ -1,3 +1,8 @@ +2.17.0 +----------- + +- Change `Sidekiq::Client.push_bulk` to return array of pushed `jid`s. + 2.16.1 -----------