From 2d0bff63512c5949964c75a2e450a129538dd773 Mon Sep 17 00:00:00 2001 From: Artur Cygan Date: Wed, 17 Dec 2014 21:09:20 +0100 Subject: [PATCH] Further style improvements --- lib/sidekiq/api.rb | 4 ++-- lib/sidekiq/middleware/server/retry_jobs.rb | 4 ++-- lib/sidekiq/util.rb | 4 ++-- lib/sidekiq/web.rb | 10 +++++----- lib/sidekiq/web_helpers.rb | 8 ++++---- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/sidekiq/api.rb b/lib/sidekiq/api.rb index 6f15e267..20dde163 100644 --- a/lib/sidekiq/api.rb +++ b/lib/sidekiq/api.rb @@ -382,7 +382,7 @@ module Sidekiq end def size - Sidekiq.redis {|c| c.zcard(name) } + Sidekiq.redis { |c| c.zcard(name) } end def clear @@ -411,7 +411,7 @@ module Sidekiq range_start = page * page_size + offset_size range_end = page * page_size + offset_size + (page_size - 1) elements = Sidekiq.redis do |conn| - conn.zrange name, range_start, range_end, :with_scores => true + conn.zrange name, range_start, range_end, with_scores: true end break if elements.empty? page -= 1 diff --git a/lib/sidekiq/middleware/server/retry_jobs.rb b/lib/sidekiq/middleware/server/retry_jobs.rb index 79c22650..cf0ed72a 100644 --- a/lib/sidekiq/middleware/server/retry_jobs.rb +++ b/lib/sidekiq/middleware/server/retry_jobs.rb @@ -143,7 +143,7 @@ module Sidekiq worker.sidekiq_retries_exhausted_block.call(msg) end rescue => e - handle_exception(e, { :context => "Error calling retries_exhausted for #{worker.class}", :job => msg }) + handle_exception(e, { context: "Error calling retries_exhausted for #{worker.class}", job: msg }) end send_to_morgue(msg) unless msg['dead'] == false @@ -183,7 +183,7 @@ module Sidekiq begin worker.sidekiq_retry_in_block.call(count) rescue Exception => e - handle_exception(e, { :context => "Failure scheduling retry using the defined `sidekiq_retry_in` in #{worker.class.name}, falling back to default" }) + handle_exception(e, { context: "Failure scheduling retry using the defined `sidekiq_retry_in` in #{worker.class.name}, falling back to default" }) nil end end diff --git a/lib/sidekiq/util.rb b/lib/sidekiq/util.rb index 1b3d3f94..223be3a7 100644 --- a/lib/sidekiq/util.rb +++ b/lib/sidekiq/util.rb @@ -14,7 +14,7 @@ module Sidekiq def watchdog(last_words) yield rescue Exception => ex - handle_exception(ex, { :context => last_words }) + handle_exception(ex, { context: last_words }) raise ex end @@ -39,7 +39,7 @@ module Sidekiq begin block.call rescue => ex - handle_exception(ex, { :event => event }) + handle_exception(ex, { event: event }) end end end diff --git a/lib/sidekiq/web.rb b/lib/sidekiq/web.rb index c66b005e..d0bbefdf 100644 --- a/lib/sidekiq/web.rb +++ b/lib/sidekiq/web.rb @@ -69,7 +69,7 @@ module Sidekiq @name = params[:name] @queue = Sidekiq::Queue.new(@name) (@current_page, @total_size, @messages) = page("queue:#{@name}", params[:page], @count) - @messages = @messages.map {|msg| Sidekiq::Job.new(msg, @name) } + @messages = @messages.map { |msg| Sidekiq::Job.new(msg, @name) } erb :queue end @@ -85,8 +85,8 @@ module Sidekiq get '/morgue' do @count = (params[:count] || 25).to_i - (@current_page, @total_size, @dead) = page("dead", params[:page], @count, :reverse => true) - @dead = @dead.map {|msg, score| Sidekiq::SortedEntry.new(nil, score, msg) } + (@current_page, @total_size, @dead) = page("dead", params[:page], @count, reverse: true) + @dead = @dead.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) } erb :morgue end @@ -128,7 +128,7 @@ module Sidekiq get '/retries' do @count = (params[:count] || 25).to_i (@current_page, @total_size, @retries) = page("retry", params[:page], @count) - @retries = @retries.map {|msg, score| Sidekiq::SortedEntry.new(nil, score, msg) } + @retries = @retries.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) } erb :retries end @@ -167,7 +167,7 @@ module Sidekiq get '/scheduled' do @count = (params[:count] || 25).to_i (@current_page, @total_size, @scheduled) = page("schedule", params[:page], @count) - @scheduled = @scheduled.map {|msg, score| Sidekiq::SortedEntry.new(nil, score, msg) } + @scheduled = @scheduled.map { |msg, score| Sidekiq::SortedEntry.new(nil, score, msg) } erb :scheduled end diff --git a/lib/sidekiq/web_helpers.rb b/lib/sidekiq/web_helpers.rb index 2280835d..3c9eb88a 100644 --- a/lib/sidekiq/web_helpers.rb +++ b/lib/sidekiq/web_helpers.rb @@ -65,7 +65,7 @@ module Sidekiq end def namespace - @@ns ||= Sidekiq.redis {|conn| conn.respond_to?(:namespace) ? conn.namespace : nil } + @@ns ||= Sidekiq.redis { |conn| conn.respond_to?(:namespace) ? conn.namespace : nil } end def redis_info @@ -110,9 +110,9 @@ module Sidekiq # Merge options with current params, filter safe params, and stringify to query string def qparams(options) options = options.stringify_keys - params.merge(options).map { |key, value| + params.merge(options).map do |key, value| SAFE_QPARAMS.include?(key) ? "#{key}=#{value}" : next - }.join("&") + end.join("&") end def truncate(text, truncate_after_chars = 2000) @@ -147,7 +147,7 @@ module Sidekiq return number end - options = {:delimiter => ',', :separator => '.'} + options = {delimiter: ',', separator: '.'} parts = number.to_s.to_str.split('.') parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{options[:delimiter]}") parts.join(options[:separator])