Skip to content
This repository has been archived by the owner on Sep 10, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1 from Xenapto/develop
Browse files Browse the repository at this point in the history
Fix non-rate-limit exception exception
  • Loading branch information
dominicsayers committed Jan 15, 2016
2 parents 4dff11b + 77c0353 commit 4ab3996
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 25 deletions.
4 changes: 4 additions & 0 deletions .hound.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
ruby:
enabled: true
config_file: .rubocop.yml
46 changes: 46 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
AllCops:
Exclude:
- 'tmp/**/*'
- 'coverage/**/*'
- 'spec/dummy/**/*'

#-------------------------------------------------------------------------------
# Project standards
#-------------------------------------------------------------------------------
StringLiterals:
EnforcedStyle: single_quotes
Enabled: true

DotPosition:
Description: 'Checks the position of the dot in multi-line method calls.'
EnforcedStyle: leading
Enabled: true

Documentation:
Description: 'Document classes and non-namespace modules.'
Enabled: false

FileName:
Description: 'Use snake_case for source file names.'
Enabled: true

Style/SymbolArray:
Description: 'Use %i or %I for arrays of symbols.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-i'
Enabled: false # Only available in Ruby 2.0+

Style/ExtraSpacing:
Description: 'Do not use unnecessary spacing.'
Enabled: true

Lint/LiteralInInterpolation:
Description: 'Avoid interpolating literals in strings'
AutoCorrect: true

#-------------------------------------------------------------------------------
# These rules have been relaxed because of existing code
# We should tighten these up over time
#-------------------------------------------------------------------------------
LineLength:
Max: 166 # project standard is 120
16 changes: 16 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
guard :rubocop do
watch(/.+\.rb$/)
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
end

guard(
:rspec,
all_after_pass: true,
all_on_start: true,
cmd: 'NO_SIMPLECOV=true bundle exec rspec --fail-fast --format documentation'
) do
watch(%r{spec/.+_spec\.rb$})
watch(%r{lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { 'spec' }
watch(%r{^spec/support/.+\.rb$}) { 'spec' }
end
3 changes: 1 addition & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
require "bundler/gem_tasks"

require 'bundler/gem_tasks'
1 change: 1 addition & 0 deletions lib/resque/plugins/rate_limited_queue/apis/evernote_queue.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class EvernoteQueue < BaseApiQueue
def self.perform(klass, *params)
super
rescue Evernote::EDAM::Error::EDAMSystemException => e
raise unless e.errorCode == Evernote::EDAM::Error::EDAMErrorCode::RATE_LIMIT_REACHED
pause_until(Time.now + 60 * e.rateLimitDuration.seconds)
rate_limited_requeue(self, klass, *params)
end
Expand Down
34 changes: 17 additions & 17 deletions resque-rate_limited_queue.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,36 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'resque-rate_limited_queue/version'

Gem::Specification.new do |spec|
spec.name = "resque-rate_limited_queue"
spec.name = 'resque-rate_limited_queue'
spec.version = RateLimitedQueue::VERSION
spec.authors = ["Greg Dowling"]
spec.email = ["mail@greddowling.com"]
spec.summary = %q{A Resque plugin to help manage jobs that use rate limited apis, pausing when you hit the limits and restarting later.}
spec.description = %q{A Resque plugin which allows you to create dedicated queues for jobs that use rate limited apis.
spec.authors = ['Greg Dowling']
spec.email = ['mail@greddowling.com']
spec.summary = 'A Resque plugin to help manage jobs that use rate limited apis, pausing when you hit the limits and restarting later.'
spec.description = 'A Resque plugin which allows you to create dedicated queues for jobs that use rate limited apis.
These queues will pause when one of the jobs hits a rate limit, and unpause after a suitable time period.
The rate_limited_queue can be used directly, and just requires catching the rate limit exception and pausing the
queue. There are also additional queues provided that already include the pause/rety logic for twitter, angelist
and evernote; these allow you to support rate limited apis with minimal changes.}
and evernote; these allow you to support rate limited apis with minimal changes.'

spec.homepage = "http://github.com/pavoni/resque-rate-limited-queue"
spec.license = "MIT"
spec.homepage = 'http://github.com/pavoni/resque-rate-limited-queue'
spec.license = 'MIT'

spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]
spec.require_paths = ['lib']

spec.add_dependency 'resque', '~> 1.9', '>= 1.9.10'
spec.add_dependency 'redis-mutex','~> 4.0', '>= 4.0.0'
spec.add_dependency 'redis-mutex', '~> 4.0', '>= 4.0.0'

spec.add_dependency "angellist_api", '~> 1.0', '>= 1.0.7'
spec.add_dependency "evernote-thrift", '~> 1.25', '>= 1.25.1'
spec.add_dependency "twitter", '~> 5.11', '>= 5.11.0'
spec.add_dependency 'angellist_api', '~> 1.0', '>= 1.0.7'
spec.add_dependency 'evernote-thrift', '~> 1.25', '>= 1.25.1'
spec.add_dependency 'twitter', '~> 5.11', '>= 5.11.0'

spec.add_development_dependency "bundler", "~> 1.7"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 2.6"
spec.add_development_dependency "simplecov", '~> 0.9.1'
spec.add_development_dependency 'bundler', '~> 1.7'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 2.6'
spec.add_development_dependency 'simplecov', '~> 0.9.1'
spec.add_development_dependency 'gem-release', '~> 0.7'
spec.add_development_dependency 'guard', '~> 2.12'
spec.add_development_dependency 'guard-rspec', '~> 4.1', '>= 4.1.1'
Expand Down
2 changes: 1 addition & 1 deletion spec/apis/angellist_queue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class RateLimitedTestQueueAL
def self.perform(succeed)
raise(AngellistApi::Error::TooManyRequests, 'error') unless succeed
fail(AngellistApi::Error::TooManyRequests, 'error') unless succeed
end
end

Expand Down
24 changes: 22 additions & 2 deletions spec/apis/evernote_queue_spec.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@ def self.seconds

class RateLimitedTestQueueEn
def self.perform(succeed)
raise(Evernote::EDAM::Error::EDAMSystemException, rateLimitDuration: RateLimitDuration) unless succeed
fail(
Evernote::EDAM::Error::EDAMSystemException,
errorCode: Evernote::EDAM::Error::EDAMErrorCode::RATE_LIMIT_REACHED,
rateLimitDuration: RateLimitDuration
) unless succeed
end
end

class RateLimitedTestQueueOther
def self.perform
fail(Evernote::EDAM::Error::EDAMSystemException)
end
end

Expand Down Expand Up @@ -51,6 +61,16 @@ def self.perform(succeed)
.enqueue(RateLimitedTestQueueEn, false)
end
end

context 'with exception that is not rate limit' do
before do
Resque::Plugins::RateLimitedQueue::EvernoteQueue.stub(:rate_limited_requeue)
end
it 'raises the exception when request fails' do
expect do
Resque::Plugins::RateLimitedQueue::EvernoteQueue.enqueue(RateLimitedTestQueueOther)
end.to raise_error Evernote::EDAM::Error::EDAMSystemException
end
end
end
end

2 changes: 1 addition & 1 deletion spec/apis/twitter_queue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class RateLimitedTestQueueTw
def self.perform(succeed)
raise(Twitter::Error::TooManyRequests
fail(Twitter::Error::TooManyRequests
.new('', 'x-rate-limit-reset' => (Time.now + 60).to_i)) unless succeed
end
end
Expand Down
1 change: 0 additions & 1 deletion spec/rate_limited_un_pause_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,4 @@ class RateLimitedTestQueue
.to eq(Resque::Plugins::RateLimitedQueue::UnPause)
end
end

end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

SimpleCov.start

RSpec.configure do |config|
RSpec.configure do |_config|
# Use database 15 for testing so we don't accidentally step on your real data.
RedisClassy.redis = Redis.new(db: 15)
unless RedisClassy.keys.empty?
Expand Down

0 comments on commit 4ab3996

Please sign in to comment.