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 +5 -5
- data/.ruby-version +1 -1
- data/Gemfile +3 -2
- data/Rakefile +14 -10
- data/VERSION +1 -1
- data/lib/metered_raven_error_handler.rb +15 -4
- data/sidekiq_metered_exceptions.gemspec +20 -17
- data/spec/sidekiq_metered_exceptions_spec.rb +74 -0
- data/{test/helper.rb → spec/spec_helper.rb} +4 -2
- metadata +31 -18
- data/test/test_sidekiq_metered_exceptions.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 56422876f36311742587f82a042322fa3a0d3dad131b97e88fc4b2c07333b4ca
|
4
|
+
data.tar.gz: c790384cdc16e828fe6a246a3aea55dad3cd2b95b875993775b6ce96f1b56636
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c7a7331f793110bcd5c3b5cd9b37125ec0f6cde1b33b1203695c6011238d3b104c6d1a3bd30b44c4dd8c44d1902cd519f63f0064987eee40391d899f66543c1
|
7
|
+
data.tar.gz: 9f4a7c2732f6b136e8e2d54b0e96cba380418a07613b9140064fea09defbddee4c8bf49f136f23c21f79194303c109a0f7189bcf47a96ee2b8ac359f57c4704b
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
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 '
|
8
|
+
gem 'rspec'
|
8
9
|
gem 'rdoc', '~> 6.0'
|
9
10
|
gem 'bundler'
|
10
|
-
gem '
|
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 '
|
15
|
-
|
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
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
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 => :
|
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.
|
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
|
20
|
-
#
|
21
|
-
#
|
22
|
-
|
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
|
1
|
+
# Generated by juwelier
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit
|
3
|
+
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: sidekiq_metered_exceptions 0.
|
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.
|
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 = "
|
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
|
-
"
|
34
|
-
"
|
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 = "
|
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, ["
|
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.
|
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<
|
51
|
+
s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
|
51
52
|
else
|
52
|
-
s.add_dependency(%q<sidekiq>.freeze, ["
|
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<
|
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<
|
59
|
+
s.add_dependency(%q<juwelier>.freeze, [">= 0"])
|
58
60
|
end
|
59
61
|
else
|
60
|
-
s.add_dependency(%q<sidekiq>.freeze, ["
|
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<
|
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<
|
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
|
-
|
11
|
-
require '
|
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.
|
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:
|
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:
|
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:
|
104
|
+
name: juwelier
|
91
105
|
requirement: !ruby/object:Gem::Requirement
|
92
106
|
requirements:
|
93
|
-
- - "
|
107
|
+
- - ">="
|
94
108
|
- !ruby/object:Gem::Version
|
95
|
-
version: '
|
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: '
|
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
|
-
-
|
123
|
-
-
|
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
|
-
|
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
|