From c911adb66769bdc8479ae59949feacf683b36429 Mon Sep 17 00:00:00 2001 From: Ryan Schlesinger Date: Mon, 26 Jan 2015 12:43:12 -0800 Subject: [PATCH 1/2] Clean up logic and docs for Client#push(_bulk) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Client#raw_push always returns true now. Therefore, there is no need to check for a false return value and Client#push can’t return nil. --- lib/sidekiq/client.rb | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/sidekiq/client.rb b/lib/sidekiq/client.rb index f5cba6ff4..48db42d4b 100644 --- a/lib/sidekiq/client.rb +++ b/lib/sidekiq/client.rb @@ -55,7 +55,7 @@ def initialize(redis_pool=nil) # All options must be strings, not symbols. NB: because we are serializing to JSON, all # symbols in 'args' will be converted to strings. # - # Returns nil if not pushed to Redis or a unique Job ID if pushed. + # Returns a unique Job ID. # # Example: # push('queue' => 'my_queue', 'class' => MyWorker, 'args' => ['foo', 1, :bat => 'bar']) @@ -64,9 +64,8 @@ def push(item) normed = normalize_item(item) payload = process_single(item['class'], normed) - pushed = false - pushed = raw_push([payload]) if payload - pushed ? payload['jid'] : nil + raw_push([payload]) if payload + payload['jid'] end ## @@ -80,9 +79,8 @@ def push(item) # is run through the client middleware pipeline and each job gets its own Job ID # as normal. # - # 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. + # Returns an array of the of pushed jobs' jids. 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) normed = normalize_item(items) payloads = items['args'].map do |args| @@ -90,9 +88,8 @@ def push_bulk(items) process_single(items['class'], normed.merge('args' => args, 'jid' => SecureRandom.hex(12), 'enqueued_at' => Time.now.to_f)) end.compact - pushed = false - pushed = raw_push(payloads) if !payloads.empty? - pushed ? payloads.collect { |payload| payload['jid'] } : nil + raw_push(payloads) if !payloads.empty? + payloads.collect { |payload| payload['jid'] } end # Allows sharding of jobs across any number of Redis instances. All jobs From d748e54b48fddc90031cbda3001494b20dfb237a Mon Sep 17 00:00:00 2001 From: Ryan Schlesinger Date: Mon, 26 Jan 2015 13:17:54 -0800 Subject: [PATCH 2/2] =?UTF-8?q?Clarify=20middleware=E2=80=99s=20role;=20fi?= =?UTF-8?q?x=20busted=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/sidekiq/client.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/sidekiq/client.rb b/lib/sidekiq/client.rb index 48db42d4b..f59c70609 100644 --- a/lib/sidekiq/client.rb +++ b/lib/sidekiq/client.rb @@ -55,7 +55,7 @@ def initialize(redis_pool=nil) # All options must be strings, not symbols. NB: because we are serializing to JSON, all # symbols in 'args' will be converted to strings. # - # Returns a unique Job ID. + # Returns a unique Job ID. If middleware stops the job, nil will be returned instead. # # Example: # push('queue' => 'my_queue', 'class' => MyWorker, 'args' => ['foo', 1, :bat => 'bar']) @@ -64,8 +64,10 @@ def push(item) normed = normalize_item(item) payload = process_single(item['class'], normed) - raw_push([payload]) if payload - payload['jid'] + if payload + raw_push([payload]) + payload['jid'] + end end ##