From 4b410d3d949a1c99bc052b6ac269a88fa141422c Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Tue, 9 Oct 2018 02:03:21 +0000 Subject: [PATCH] Auto corrected by following Ruby Space --- lib/resque/plugins/restriction.rb | 16 ++++++++-------- spec/resque/job_spec.rb | 6 +++--- spec/resque/plugins/restriction_spec.rb | 22 +++++++++++----------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/resque/plugins/restriction.rb b/lib/resque/plugins/restriction.rb index ed01c21..f6e09ed 100644 --- a/lib/resque/plugins/restriction.rb +++ b/lib/resque/plugins/restriction.rb @@ -4,11 +4,11 @@ module Restriction SECONDS = { :per_second => 1, :per_minute => 60, - :per_hour => 60*60, - :per_day => 24*60*60, - :per_week => 7*24*60*60, - :per_month => 31*24*60*60, - :per_year => 366*24*60*60 + :per_hour => 60 * 60, + :per_day => 24 * 60 * 60, + :per_week => 7 * 24 * 60 * 60, + :per_month => 31 * 24 * 60 * 60, + :per_year => 366 * 24 * 60 * 60 } RESTRICTION_QUEUE_PREFIX = 'restriction' @@ -16,7 +16,7 @@ def settings @options ||= {} end - def restrict(options={}) + def restrict(options = {}) settings.merge!(options) end @@ -30,7 +30,7 @@ def before_perform_restriction(*args) # first try to set period key to be the total allowed for the period # if we get a 0 result back, the key wasn't set, so we know we are # already tracking the count for that period' - period_active = ! Resque.redis.setnx(key, number.to_i - 1) + period_active = !Resque.redis.setnx(key, number.to_i - 1) # If we are already tracking that period, then decrement by one to # see if we are allowed to run, pushing to restriction queue to run # later if not. Note that the value stored is the number of outstanding @@ -42,7 +42,7 @@ def before_perform_restriction(*args) if value < 0 # reincrement the keys if one of the periods triggers DontPerform so # that we accurately track capacity - keys_decremented.each {|k| Resque.redis.incrby(k, 1) } + keys_decremented.each { |k| Resque.redis.incrby(k, 1) } Resque.push restriction_queue_name, :class => to_s, :args => args raise Resque::Job::DontPerform end diff --git a/spec/resque/job_spec.rb b/spec/resque/job_spec.rb index 8f352b8..bfb9370 100644 --- a/spec/resque/job_spec.rb +++ b/spec/resque/job_spec.rb @@ -7,7 +7,7 @@ it "should repush restriction queue when reserve" do Resque.push('restriction_normal', :class => 'OneHourRestrictionJob', :args => ['any args']) - expect(Resque::Job.reserve('restriction_normal')).to eq Resque::Job.new('restriction_normal', {'class' => 'OneHourRestrictionJob', 'args' => ['any args']}) + expect(Resque::Job.reserve('restriction_normal')).to eq Resque::Job.new('restriction_normal', { 'class' => 'OneHourRestrictionJob', 'args' => ['any args'] }) expect(Resque::Job.reserve('restriction_normal')).to be_nil expect(Resque::Job.reserve('normal')).to be_nil end @@ -16,13 +16,13 @@ Resque.redis.set(OneHourRestrictionJob.redis_key(:per_hour), -1) Resque.push('restriction_normal', :class => 'OneHourRestrictionJob', :args => ['any args']) expect(Resque::Job.reserve('restriction_normal')).to be_nil - expect(Resque.pop('restriction_normal')).to eq({'class' => 'OneHourRestrictionJob', 'args' => ['any args']}) + expect(Resque.pop('restriction_normal')).to eq({ 'class' => 'OneHourRestrictionJob', 'args' => ['any args'] }) expect(Resque::Job.reserve('normal')).to be_nil end it "should not repush when reserve normal queue" do Resque.push('normal', :class => 'OneHourRestrictionJob', :args => ['any args']) - expect(Resque::Job.reserve('normal')).to eq Resque::Job.new('normal', {'class' => 'OneHourRestrictionJob', 'args' => ['any args']}) + expect(Resque::Job.reserve('normal')).to eq Resque::Job.new('normal', { 'class' => 'OneHourRestrictionJob', 'args' => ['any args'] }) expect(Resque::Job.reserve('normal')).to be_nil expect(Resque::Job.reserve('restriction_normal')).to be_nil end diff --git a/spec/resque/plugins/restriction_spec.rb b/spec/resque/plugins/restriction_spec.rb index 4044f0c..9277c55 100644 --- a/spec/resque/plugins/restriction_spec.rb +++ b/spec/resque/plugins/restriction_spec.rb @@ -8,8 +8,8 @@ context "redis_key" do it "should get redis_key with different period" do expect(MyJob.redis_key(:per_minute)).to eq "restriction:MyJob:#{Time.now.to_i / 60}" - expect(MyJob.redis_key(:per_hour)).to eq "restriction:MyJob:#{Time.now.to_i / (60*60)}" - expect(MyJob.redis_key(:per_day)).to eq "restriction:MyJob:#{Time.now.to_i / (24*60*60)}" + expect(MyJob.redis_key(:per_hour)).to eq "restriction:MyJob:#{Time.now.to_i / (60 * 60)}" + expect(MyJob.redis_key(:per_day)).to eq "restriction:MyJob:#{Time.now.to_i / (24 * 60 * 60)}" expect(MyJob.redis_key(:per_month)).to eq "restriction:MyJob:#{Date.today.strftime("%Y-%m")}" expect(MyJob.redis_key(:per_year)).to eq "restriction:MyJob:#{Date.today.year}" expect(MyJob.redis_key(:per_minute_and_foo, 'foo' => 'bar')).to eq "restriction:MyJob:bar:#{Time.now.to_i / 60}" @@ -25,11 +25,11 @@ context "seconds" do it "should get seconds with different period" do expect(MyJob.seconds(:per_minute)).to eq 60 - expect(MyJob.seconds(:per_hour)).to eq 60*60 - expect(MyJob.seconds(:per_day)).to eq 24*60*60 - expect(MyJob.seconds(:per_week)).to eq 7*24*60*60 - expect(MyJob.seconds(:per_month)).to eq 31*24*60*60 - expect(MyJob.seconds(:per_year)).to eq 366*24*60*60 + expect(MyJob.seconds(:per_hour)).to eq 60 * 60 + expect(MyJob.seconds(:per_day)).to eq 24 * 60 * 60 + expect(MyJob.seconds(:per_week)).to eq 7 * 24 * 60 * 60 + expect(MyJob.seconds(:per_month)).to eq 31 * 24 * 60 * 60 + expect(MyJob.seconds(:per_year)).to eq 366 * 24 * 60 * 60 expect(MyJob.seconds(:per_minute_and_foo)).to eq 60 end @@ -42,10 +42,10 @@ context "settings" do it "get correct number to restriction jobs" do - expect(OneDayRestrictionJob.settings).to eq({:per_day => 100}) - expect(OneHourRestrictionJob.settings).to eq({:per_hour => 10}) - expect(MultipleRestrictionJob.settings).to eq({:per_hour => 10, :per_300 => 2}) - expect(MultiCallRestrictionJob.settings).to eq({:per_hour => 10, :per_300 => 2}) + expect(OneDayRestrictionJob.settings).to eq({ :per_day => 100 }) + expect(OneHourRestrictionJob.settings).to eq({ :per_hour => 10 }) + expect(MultipleRestrictionJob.settings).to eq({ :per_hour => 10, :per_300 => 2 }) + expect(MultiCallRestrictionJob.settings).to eq({ :per_hour => 10, :per_300 => 2 }) end end