sidekiq-configure_notifications 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +25 -0
- data/Rakefile +11 -0
- data/lib/sidekiq/configure_notifications/exception_handler.rb +14 -0
- data/lib/sidekiq/configure_notifications/version.rb +5 -0
- data/lib/sidekiq/configure_notifications.rb +2 -0
- data/sidekiq-configure_notifications.gemspec +27 -0
- data/test/helper.rb +20 -0
- data/test/test_exception_handler.rb +75 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e509db53279de6d0008868bb571073722284cd10
|
4
|
+
data.tar.gz: bed4f1f553730e5d8c0c70c651794d1650275960
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8b7360f2bfab033ff53142985489aa58975abf19435fe7ce35efd37f54d1177a140c1e8d69fde724eed6f75d59dfb0a8cd87067fb08f9a1f6cfdd79a0ff1c887
|
7
|
+
data.tar.gz: 5659cef2f9833e741f5e164a0681bb42c5f0139a97f33ce794378d8b89cca04d7bab77860a196ab792e2a5ee7bfc080b481eea05433975abd0361053380e2f10
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Caue Guerra
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
This plugin allows you to define after how many retries an exception should be nofitied to Honeybadger, Newrelic, etc
|
2
|
+
|
3
|
+
To use it, just install this gem:
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
gem 'sidekiq'
|
7
|
+
gem 'sidekiq-configure_notifications'
|
8
|
+
```
|
9
|
+
|
10
|
+
Now, on your worker you can just add :log_exceptions_after => x and :skip_log_exceptions => [Exception, MyCustomError]
|
11
|
+
|
12
|
+
as in:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
class MyWorker
|
16
|
+
include Sidekiq::Worker
|
17
|
+
sidekiq_options :log_exceptions_after => 8, :skip_log_exceptions => [Exception, MyCustomError]
|
18
|
+
|
19
|
+
def perform(user_id)
|
20
|
+
raise Exception.new
|
21
|
+
end
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
This code will keep retrying, but will only notify external services after 8 retries. Also, all the exceptions that are not "Exception" or "MyCustomError" will be notified as usual. If you don't use the skip_log_exceptions option, all exceptions will be only logged after 8 retries
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'sidekiq'
|
2
|
+
|
3
|
+
module Sidekiq
|
4
|
+
module ExceptionHandler
|
5
|
+
alias_method :handle_exception_original, :handle_exception
|
6
|
+
|
7
|
+
def handle_exception(ex, msg)
|
8
|
+
if msg['retry_count'].to_i >= msg['log_exceptions_after'].to_i &&
|
9
|
+
(msg['skip_log_exceptions'].nil? || msg['skip_log_exceptions'].size == 0 || msg['skip_log_exceptions'].include?(ex.class))
|
10
|
+
handle_exception_original(ex, msg)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sidekiq/configure_notifications'
|
5
|
+
require 'sidekiq/configure_notifications/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "sidekiq-configure_notifications"
|
9
|
+
spec.version = Sidekiq::ConfigureNotifications::VERSION
|
10
|
+
spec.authors = ["Caue Guerra"]
|
11
|
+
spec.email = ["caueguerra@gmail.com"]
|
12
|
+
spec.description = %q{This plugin allows you to define after how many retries an exception should be nofitied to Honeybadger, Newrelic, etc}
|
13
|
+
spec.summary = %q{This plugin allows you to define after how many retries an exception should be nofitied to Honeybadger, Newrelic, etc}
|
14
|
+
spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency 'sidekiq', '~> 2.13.0'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency 'minitest', '~> 5'
|
27
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
begin
|
2
|
+
require 'pry'
|
3
|
+
rescue LoadError
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'minitest/autorun'
|
7
|
+
require 'minitest/pride'
|
8
|
+
|
9
|
+
require 'celluloid/autostart'
|
10
|
+
require 'sidekiq'
|
11
|
+
require 'sidekiq/util'
|
12
|
+
Sidekiq.logger.level = Logger::ERROR
|
13
|
+
|
14
|
+
require 'sidekiq/redis_connection'
|
15
|
+
redis_url = ENV['REDIS_URL'] || 'redis://localhost/15'
|
16
|
+
REDIS = Sidekiq::RedisConnection.create(:url => redis_url, :namespace => 'testy')
|
17
|
+
|
18
|
+
Sidekiq.configure_client do |config|
|
19
|
+
config.redis = { :url => redis_url, :namespace => 'testy' }
|
20
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'sidekiq'
|
3
|
+
require 'sidekiq/exception_handler'
|
4
|
+
require 'sidekiq/configure_notifications/exception_handler'
|
5
|
+
require 'stringio'
|
6
|
+
require 'logger'
|
7
|
+
|
8
|
+
ExceptionHandlerTestException = Class.new(StandardError)
|
9
|
+
TEST_EXCEPTION = ExceptionHandlerTestException.new("Something didn't work!")
|
10
|
+
|
11
|
+
class Component
|
12
|
+
include Sidekiq::ExceptionHandler
|
13
|
+
|
14
|
+
def invoke_exception(args)
|
15
|
+
raise TEST_EXCEPTION
|
16
|
+
rescue ExceptionHandlerTestException => e
|
17
|
+
handle_exception(e,args)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class TestExceptionHandler < Minitest::Test
|
22
|
+
describe "with log_exceptions_after and skip_log_exceptions options" do
|
23
|
+
after do
|
24
|
+
Object.send(:remove_const, "Airbrake") # HACK should probably inject Airbrake etc into this class in the future
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "does not log" do
|
28
|
+
before do
|
29
|
+
class ::Airbrake
|
30
|
+
def self.notify_or_ignore(*args)
|
31
|
+
raise "it should not be called"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "does not log when number of retries is less than log_exceptions_after" do
|
37
|
+
Component.new.invoke_exception('log_exceptions_after' => 4, 'retry_count' => 3)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "does not log when number of retries is bigger than log_exceptions_after and exception is not in skip_log_exceptions" do
|
41
|
+
Component.new.invoke_exception('log_exceptions_after' => 2, 'retry_count' => 3, 'skip_log_exceptions' => [::Exception])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "logs" do
|
46
|
+
before do
|
47
|
+
::Airbrake = Minitest::Mock.new
|
48
|
+
end
|
49
|
+
|
50
|
+
it "logs when number of retries is less than log_exceptions_after and exception is not in skip_log_exceptions 3" do
|
51
|
+
::Airbrake.expect(:notify_or_ignore,nil,[TEST_EXCEPTION,:parameters => { 'log_exceptions_after' => 2, 'retry_count' => 3, 'skip_log_exceptions' => [ExceptionHandlerTestException] }])
|
52
|
+
Component.new.invoke_exception('log_exceptions_after' => 2, 'retry_count' => 3, 'skip_log_exceptions' => [ExceptionHandlerTestException])
|
53
|
+
::Airbrake.verify
|
54
|
+
end
|
55
|
+
|
56
|
+
it "logs when number of retries is less than log_exceptions_after and skip_log_exceptions is empty" do
|
57
|
+
::Airbrake.expect(:notify_or_ignore,nil,[TEST_EXCEPTION,:parameters => { 'log_exceptions_after' => 2, 'retry_count' => 3, 'skip_log_exceptions' => [] }])
|
58
|
+
Component.new.invoke_exception('log_exceptions_after' => 2, 'retry_count' => 3, 'skip_log_exceptions' => [])
|
59
|
+
::Airbrake.verify
|
60
|
+
end
|
61
|
+
|
62
|
+
it "logs when number of retries is less than log_exceptions_after and skip_log_exceptions is not given" do
|
63
|
+
::Airbrake.expect(:notify_or_ignore,nil,[TEST_EXCEPTION,:parameters => { 'log_exceptions_after' => 2, 'retry_count' => 3 }])
|
64
|
+
Component.new.invoke_exception('log_exceptions_after' => 2, 'retry_count' => 3)
|
65
|
+
::Airbrake.verify
|
66
|
+
end
|
67
|
+
|
68
|
+
it "logs when log_exceptions_after is not given" do
|
69
|
+
::Airbrake.expect(:notify_or_ignore,nil,[TEST_EXCEPTION,:parameters => {}])
|
70
|
+
Component.new.invoke_exception({})
|
71
|
+
::Airbrake.verify
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sidekiq-configure_notifications
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Caue Guerra
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sidekiq
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.13.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.13.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5'
|
69
|
+
description: This plugin allows you to define after how many retries an exception
|
70
|
+
should be nofitied to Honeybadger, Newrelic, etc
|
71
|
+
email:
|
72
|
+
- caueguerra@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- lib/sidekiq/configure_notifications.rb
|
83
|
+
- lib/sidekiq/configure_notifications/exception_handler.rb
|
84
|
+
- lib/sidekiq/configure_notifications/version.rb
|
85
|
+
- sidekiq-configure_notifications.gemspec
|
86
|
+
- test/helper.rb
|
87
|
+
- test/test_exception_handler.rb
|
88
|
+
homepage: ''
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.0.2
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: This plugin allows you to define after how many retries an exception should
|
112
|
+
be nofitied to Honeybadger, Newrelic, etc
|
113
|
+
test_files:
|
114
|
+
- test/helper.rb
|
115
|
+
- test/test_exception_handler.rb
|