sidekiq_metered_exceptions 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0ae923f55f11631fda824789433b8bb7fc6b2f60
4
- data.tar.gz: 3406ec90499d78ae923ae9632d67efe3f495cbd9
2
+ SHA256:
3
+ metadata.gz: 56422876f36311742587f82a042322fa3a0d3dad131b97e88fc4b2c07333b4ca
4
+ data.tar.gz: c790384cdc16e828fe6a246a3aea55dad3cd2b95b875993775b6ce96f1b56636
5
5
  SHA512:
6
- metadata.gz: b564599aa0dcc387e7b5ad30e8d877a6be1502946360f2dfacc7ab83f4a4b442ae1e15311a07af6dc7f200201c0dbebd5a712df630d4c336d4d5496e93d1aedf
7
- data.tar.gz: a9544e6ce6eb4afbd50ec0acc84818ed30e9e2bce941e6cd4b57432f26473fddef981f6cdb1c5c917ee499d717b5fe151f41a421785f4994b6fc6d49e0bd5da9
6
+ metadata.gz: 4c7a7331f793110bcd5c3b5cd9b37125ec0f6cde1b33b1203695c6011238d3b104c6d1a3bd30b44c4dd8c44d1902cd519f63f0064987eee40391d899f66543c1
7
+ data.tar.gz: 9f4a7c2732f6b136e8e2d54b0e96cba380418a07613b9140064fea09defbddee4c8bf49f136f23c21f79194303c109a0f7189bcf47a96ee2b8ac359f57c4704b
@@ -1 +1 @@
1
- 2.3.3
1
+ 2.5.3
data/Gemfile CHANGED
@@ -2,10 +2,11 @@ source "http://rubygems.org"
2
2
 
3
3
  gem 'sidekiq', '>= 2.12.4', '< 6.0'
4
4
  gem 'sentry-raven', '~> 2.3'
5
+ gem 'activesupport'
5
6
 
6
7
  group :development do
7
- gem 'minitest', '>= 0'
8
+ gem 'rspec'
8
9
  gem 'rdoc', '~> 6.0'
9
10
  gem 'bundler'
10
- gem 'jeweler', '~> 2.3'
11
+ gem 'juwelier'
11
12
  end
data/Rakefile CHANGED
@@ -11,9 +11,8 @@ rescue Bundler::BundlerError => e
11
11
  end
12
12
  require 'rake'
13
13
 
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
14
+ require 'juwelier'
15
+ Juwelier::Tasks.new do |gem|
17
16
  gem.name = "sidekiq_metered_exceptions"
18
17
  gem.homepage = "http://github.com/woodhull/sidekiq_metered_exceptions"
19
18
  gem.license = "MIT"
@@ -21,18 +20,23 @@ Jeweler::Tasks.new do |gem|
21
20
  gem.description = %Q{Some exceptions are transient, so notifying an admin is not useful.}
22
21
  gem.email = "woodhull@gmail.com"
23
22
  gem.authors = ["Nathan Woodhull"]
23
+
24
24
  # dependencies defined in Gemfile
25
25
  end
26
- Jeweler::RubygemsDotOrgTasks.new
26
+ Juwelier::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
27
33
 
28
- require 'rake/testtask'
29
- Rake::TestTask.new(:test) do |test|
30
- test.libs << 'lib' << 'test'
31
- test.pattern = 'test/**/test_*.rb'
32
- test.verbose = true
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
33
37
  end
34
38
 
35
- task :default => :test
39
+ task :default => :spec
36
40
 
37
41
  require 'rdoc/task'
38
42
  Rake::RDocTask.new do |rdoc|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
1
+ 0.4.0
@@ -1,8 +1,15 @@
1
1
  require 'sidekiq'
2
+ require 'active_support/core_ext/hash' # for deep_symbolize_keys
2
3
  require 'raven/integrations/sidekiq'
3
4
 
4
5
  module SidekiqMeteredExceptions
5
6
  class MeteredRavenErrorHandler < ::Raven::SidekiqErrorHandler
7
+ attr_reader :errors_to_ignore_on_first_occurrence
8
+
9
+ def initialize(errors_to_ignore_on_first_occurrence: [])
10
+ @errors_to_ignore_on_first_occurrence = errors_to_ignore_on_first_occurrence
11
+ end
12
+
6
13
  def call(ex, original_context)
7
14
  ::Rails.logger.debug("MeteredRavenErrorHandler -- Error on Sidekiq job. Exception: #{ex.inspect} - Context: #{original_context.inspect}")
8
15
 
@@ -16,10 +23,14 @@ module SidekiqMeteredExceptions
16
23
  # Is this a retryable job?
17
24
  is_retryable = context[:retry] || (context[:job] && context[:job][:retry])
18
25
 
19
- # We notify if this job has been retried at least once.
20
- # Someday we plan to make this number configurable.
21
- # If this isn't a retryable job, we notify even if this is the first attempt, because there will not be more attempts.
22
- if retry_count > 0 || !is_retryable
26
+ # We notify to Sentry unless:
27
+ # Is not one of the errors that should be ignored on first occurrence
28
+ # AND
29
+ # This job has not been retried at least once
30
+ # AND
31
+ # Sidekiq is automatically retrying the job
32
+ #
33
+ unless errors_to_ignore_on_first_occurrence.include?(ex.class) && retry_count < 1 && is_retryable
23
34
  ::Rails.logger.debug("MeteredRavenErrorHandler -- Current retry count: #{retry_count}. Notifying upstream...")
24
35
 
25
36
  super(ex, original_context)
@@ -1,17 +1,17 @@
1
- # Generated by jeweler
1
+ # Generated by juwelier
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
3
+ # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: sidekiq_metered_exceptions 0.3.4 ruby lib
5
+ # stub: sidekiq_metered_exceptions 0.4.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "sidekiq_metered_exceptions".freeze
9
- s.version = "0.3.4"
9
+ s.version = "0.4.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Nathan Woodhull".freeze]
14
- s.date = "2018-12-04"
14
+ s.date = "2019-11-06"
15
15
  s.description = "Some exceptions are transient, so notifying an admin is not useful.".freeze
16
16
  s.email = "woodhull@gmail.com".freeze
17
17
  s.extra_rdoc_files = [
@@ -30,39 +30,42 @@ Gem::Specification.new do |s|
30
30
  "lib/metered_raven_error_handler.rb",
31
31
  "lib/sidekiq_metered_exceptions.rb",
32
32
  "sidekiq_metered_exceptions.gemspec",
33
- "test/helper.rb",
34
- "test/test_sidekiq_metered_exceptions.rb"
33
+ "spec/sidekiq_metered_exceptions_spec.rb",
34
+ "spec/spec_helper.rb"
35
35
  ]
36
36
  s.homepage = "http://github.com/woodhull/sidekiq_metered_exceptions".freeze
37
37
  s.licenses = ["MIT".freeze]
38
- s.rubygems_version = "2.6.12".freeze
38
+ s.rubygems_version = "3.0.3".freeze
39
39
  s.summary = "Only propagate sidekiq exceptions that have already been retried once.".freeze
40
40
 
41
41
  if s.respond_to? :specification_version then
42
42
  s.specification_version = 4
43
43
 
44
44
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
- s.add_runtime_dependency(%q<sidekiq>.freeze, ["< 6.0", ">= 2.12.4"])
45
+ s.add_runtime_dependency(%q<sidekiq>.freeze, [">= 2.12.4", "< 6.0"])
46
46
  s.add_runtime_dependency(%q<sentry-raven>.freeze, ["~> 2.3"])
47
- s.add_development_dependency(%q<minitest>.freeze, [">= 0"])
47
+ s.add_runtime_dependency(%q<activesupport>.freeze, [">= 0"])
48
+ s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
48
49
  s.add_development_dependency(%q<rdoc>.freeze, ["~> 6.0"])
49
50
  s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
50
- s.add_development_dependency(%q<jeweler>.freeze, ["~> 2.3"])
51
+ s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
51
52
  else
52
- s.add_dependency(%q<sidekiq>.freeze, ["< 6.0", ">= 2.12.4"])
53
+ s.add_dependency(%q<sidekiq>.freeze, [">= 2.12.4", "< 6.0"])
53
54
  s.add_dependency(%q<sentry-raven>.freeze, ["~> 2.3"])
54
- s.add_dependency(%q<minitest>.freeze, [">= 0"])
55
+ s.add_dependency(%q<activesupport>.freeze, [">= 0"])
56
+ s.add_dependency(%q<rspec>.freeze, [">= 0"])
55
57
  s.add_dependency(%q<rdoc>.freeze, ["~> 6.0"])
56
58
  s.add_dependency(%q<bundler>.freeze, [">= 0"])
57
- s.add_dependency(%q<jeweler>.freeze, ["~> 2.3"])
59
+ s.add_dependency(%q<juwelier>.freeze, [">= 0"])
58
60
  end
59
61
  else
60
- s.add_dependency(%q<sidekiq>.freeze, ["< 6.0", ">= 2.12.4"])
62
+ s.add_dependency(%q<sidekiq>.freeze, [">= 2.12.4", "< 6.0"])
61
63
  s.add_dependency(%q<sentry-raven>.freeze, ["~> 2.3"])
62
- s.add_dependency(%q<minitest>.freeze, [">= 0"])
64
+ s.add_dependency(%q<activesupport>.freeze, [">= 0"])
65
+ s.add_dependency(%q<rspec>.freeze, [">= 0"])
63
66
  s.add_dependency(%q<rdoc>.freeze, ["~> 6.0"])
64
67
  s.add_dependency(%q<bundler>.freeze, [">= 0"])
65
- s.add_dependency(%q<jeweler>.freeze, ["~> 2.3"])
68
+ s.add_dependency(%q<juwelier>.freeze, [">= 0"])
66
69
  end
67
70
  end
68
71
 
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ class Rails
4
+ end
5
+
6
+ describe SidekiqMeteredExceptions::MeteredRavenErrorHandler do
7
+ describe '#initialize' do
8
+ it 'should not raise if errors_to_ignore_on_first_occurrence argument not provided' do
9
+ expect { SidekiqMeteredExceptions::MeteredRavenErrorHandler.new }.not_to raise_error ArgumentError
10
+ end
11
+
12
+ it 'should set errors_to_ignore_on_first_occurrence if provided' do
13
+ subject = SidekiqMeteredExceptions::MeteredRavenErrorHandler.new(errors_to_ignore_on_first_occurrence: [StandardError, RuntimeError])
14
+ expect(subject.errors_to_ignore_on_first_occurrence).to eq([StandardError, RuntimeError])
15
+ end
16
+ end
17
+
18
+ describe '#call' do
19
+ before :each do
20
+ allow(::Rails).to receive(:logger).and_return(double(debug: true))
21
+ end
22
+
23
+ context 'without any exceptions being reported on first occurrence' do
24
+ let(:exception) { Exception.new }
25
+
26
+ subject { SidekiqMeteredExceptions::MeteredRavenErrorHandler.new }
27
+
28
+ it 'should capture exception if it is first occurrence' do
29
+ expect(Raven).to receive(:capture_exception).with(exception, anything)
30
+
31
+ subject.call(exception, { 'retry_count' => 0, 'retry' => true })
32
+ end
33
+
34
+ it 'should capture exception if has been retried at least once' do
35
+ expect(Raven).to receive(:capture_exception).with(exception, anything)
36
+
37
+ subject.call(exception, { 'retry_count' => 1, 'retry' => true })
38
+ end
39
+ end
40
+
41
+ context 'with collection of exceptions being reported on first occurrence' do
42
+ let(:exceptions_reported_on_first_occurrence) { [ZeroDivisionError, NameError] }
43
+
44
+ subject { SidekiqMeteredExceptions::MeteredRavenErrorHandler.new(errors_to_ignore_on_first_occurrence: exceptions_reported_on_first_occurrence) }
45
+
46
+ it 'should not capture exception if it is first occurrence and is included in errors_to_ignore_on_first_occurrence' do
47
+ expect(Raven).not_to receive(:capture_exception)
48
+
49
+ subject.call(ZeroDivisionError.new, { 'retry_count' => 0, 'retry' => true })
50
+ end
51
+
52
+ it 'should capture exception if it is first occurrence and is not included in errors_to_ignore_on_first_occurrence' do
53
+ exception = StandardError.new
54
+ expect(Raven).to receive(:capture_exception).with(exception, anything)
55
+
56
+ subject.call(exception, { 'retry_count' => 0, 'retry' => true })
57
+ end
58
+
59
+ it 'should capture exception if it is first occurrence, it is not retryable and is included in errors_to_ignore_on_first_occurrence' do
60
+ exception = ZeroDivisionError.new
61
+ expect(Raven).to receive(:capture_exception).with(exception, anything)
62
+
63
+ subject.call(exception, { 'retry_count' => 0, 'retry' => false })
64
+ end
65
+
66
+ it 'should capture exception if it has been retried at least once and is included in errors_to_ignore_on_first_occurrence' do
67
+ exception = ZeroDivisionError.new
68
+ expect(Raven).to receive(:capture_exception).with(exception, anything)
69
+
70
+ subject.call(exception, { 'retry_count' => 1, 'retry' => true })
71
+ end
72
+ end
73
+ end
74
+ end
@@ -7,10 +7,12 @@ rescue Bundler::BundlerError => e
7
7
  $stderr.puts "Run `bundle install` to install missing gems"
8
8
  exit e.status_code
9
9
  end
10
- require 'minitest/autorun'
11
- require 'minitest/pride'
10
+
11
+ require 'rspec'
12
+ require 'sentry-raven'
12
13
 
13
14
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
15
  $LOAD_PATH.unshift(File.dirname(__FILE__))
15
16
  require 'sidekiq_metered_exceptions'
16
17
 
18
+
metadata CHANGED
@@ -1,35 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq_metered_exceptions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Woodhull
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-04 00:00:00.000000000 Z
11
+ date: 2019-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "<"
18
- - !ruby/object:Gem::Version
19
- version: '6.0'
20
17
  - - ">="
21
18
  - !ruby/object:Gem::Version
22
19
  version: 2.12.4
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - "<"
28
- - !ruby/object:Gem::Version
29
- version: '6.0'
30
27
  - - ">="
31
28
  - !ruby/object:Gem::Version
32
29
  version: 2.12.4
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: sentry-raven
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -45,7 +45,21 @@ dependencies:
45
45
  - !ruby/object:Gem::Version
46
46
  version: '2.3'
47
47
  - !ruby/object:Gem::Dependency
48
- name: minitest
48
+ name: activesupport
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
49
63
  requirement: !ruby/object:Gem::Requirement
50
64
  requirements:
51
65
  - - ">="
@@ -87,19 +101,19 @@ dependencies:
87
101
  - !ruby/object:Gem::Version
88
102
  version: '0'
89
103
  - !ruby/object:Gem::Dependency
90
- name: jeweler
104
+ name: juwelier
91
105
  requirement: !ruby/object:Gem::Requirement
92
106
  requirements:
93
- - - "~>"
107
+ - - ">="
94
108
  - !ruby/object:Gem::Version
95
- version: '2.3'
109
+ version: '0'
96
110
  type: :development
97
111
  prerelease: false
98
112
  version_requirements: !ruby/object:Gem::Requirement
99
113
  requirements:
100
- - - "~>"
114
+ - - ">="
101
115
  - !ruby/object:Gem::Version
102
- version: '2.3'
116
+ version: '0'
103
117
  description: Some exceptions are transient, so notifying an admin is not useful.
104
118
  email: woodhull@gmail.com
105
119
  executables: []
@@ -119,8 +133,8 @@ files:
119
133
  - lib/metered_raven_error_handler.rb
120
134
  - lib/sidekiq_metered_exceptions.rb
121
135
  - sidekiq_metered_exceptions.gemspec
122
- - test/helper.rb
123
- - test/test_sidekiq_metered_exceptions.rb
136
+ - spec/sidekiq_metered_exceptions_spec.rb
137
+ - spec/spec_helper.rb
124
138
  homepage: http://github.com/woodhull/sidekiq_metered_exceptions
125
139
  licenses:
126
140
  - MIT
@@ -140,8 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
154
  - !ruby/object:Gem::Version
141
155
  version: '0'
142
156
  requirements: []
143
- rubyforge_project:
144
- rubygems_version: 2.6.12
157
+ rubygems_version: 3.0.3
145
158
  signing_key:
146
159
  specification_version: 4
147
160
  summary: Only propagate sidekiq exceptions that have already been retried once.
@@ -1,14 +0,0 @@
1
- require 'helper'
2
-
3
- class TestSidekiqMeteredExceptions < Minitest::Test
4
- describe 'middleware' do
5
- before do
6
- @exception = Exception.new
7
- @middleware = SidekiqMeteredExceptions::MeteredRavenErrorHandler.new
8
- end
9
-
10
- # todo: figure out how to use minitest.
11
-
12
-
13
- end
14
- end