exception_notification_moderate 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ba7d707671895680667c6ea84677b1e183a2ca16
4
+ data.tar.gz: 7f3fcf7dd6cc62c5c80b18efb510f5ead07c30de
5
+ SHA512:
6
+ metadata.gz: 1d900b565b765f84391ef589751c791cabfd80579f5ac26c8a007f68f98b166200d3edb6faee2753b8f302e0a7b4cc0e06d03238784216f3b2449d688ae3c886
7
+ data.tar.gz: fc6d7df9e6c9c03bec0c96a65d822fc1dbc90f0791ed4b0a054e6af4cf7af91c1231369779450be3331ac2ea93825694901a77adfab9ea69ba83107d3264d0ad
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0
4
+ - 2.1
5
+ script:
6
+ - bundle exec rspec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in exception_notification_moderate.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 ryonext
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,42 @@
1
+ [![Build Status](https://travis-ci.org/ryonext/exception_notification_moderate.svg?branch=master)](https://travis-ci.org/ryonext/exception_notification_moderate)
2
+
3
+ # ExceptionNotificationModerate
4
+
5
+ This gem blocks same error notifications that is sended by ExceptionNotification in short time.
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'exception_notification_moderate'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install exception_notification_moderate
23
+
24
+ ## Usage
25
+
26
+ * Set Redis Host
27
+ * Set logger class
28
+
29
+ ```
30
+ ExceptionNotificationModerate.configure do |config|
31
+ config.redis_host = 'localhost:6379'
32
+ config.logger = Logger.new('./log/ex_notification.log')
33
+ end
34
+ ```
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it ( https://github.com/ryonext/exception_notification_moderate/fork )
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'exception_notification_moderate/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "exception_notification_moderate"
8
+ spec.version = ExceptionNotificationModerate::VERSION
9
+ spec.authors = ["ryonext"]
10
+ spec.email = ["ryonext.s@gmail.com"]
11
+ spec.summary = %q{Notify same exception moderate.}
12
+ spec.description = %q{When system raises same errors in short time, it blocks second and later notifications}
13
+ spec.homepage = "http://github.com/ryonext/exception_notification_moderate"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'exception_notification', "~> 4.0"
22
+ spec.add_dependency 'redis'
23
+ spec.add_dependency 'activesupport', "~> 4.0"
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "timecop"
28
+ spec.add_development_dependency "pry-byebug"
29
+ spec.add_development_dependency "mock_redis"
30
+ end
@@ -0,0 +1,10 @@
1
+ require 'exception_notification_moderate/version'
2
+ require 'active_support/configurable'
3
+ require 'exception_notifier'
4
+ require 'exception_notification_moderate/exception_notifier'
5
+
6
+ module ExceptionNotificationModerate
7
+ include ActiveSupport::Configurable
8
+ config_accessor :redis_host
9
+ config_accessor :logger
10
+ end
@@ -0,0 +1,37 @@
1
+ require 'exception_notification'
2
+ require 'redis'
3
+
4
+ module ExceptionNotifier
5
+ class << self
6
+ alias_method :original_notify_exception, :notify_exception
7
+
8
+ def notify_exception(exception, options={})
9
+ ex_key = exception_key(exception)
10
+ begin
11
+ val = redis.get(ex_key)
12
+ rescue Redis::CannotConnectError
13
+ end
14
+ if val && val.to_i + 60 > Time.now.to_i
15
+ # Write log and return.
16
+ ExceptionNotificationModerate.logger.info(exception)
17
+ return false
18
+ end
19
+
20
+ begin
21
+ redis.set(ex_key, Time.now.to_i)
22
+ rescue Redis::CannotConnectError
23
+ end
24
+ original_notify_exception(exception, options)
25
+ end
26
+
27
+ private
28
+
29
+ def exception_key(exception)
30
+ "#{exception.to_s}_#{exception.message}"
31
+ end
32
+
33
+ def redis
34
+ Redis.new(host: ExceptionNotificationModerate.redis_host)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module ExceptionNotificationModerate
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe ExceptionNotifier do
4
+ describe '.notify_exception' do
5
+ before do
6
+ ExceptionNotificationModerate.configure do |config|
7
+ config.redis_host = 'localhost'
8
+ config.logger = Logger.new(STDOUT)
9
+ end
10
+ end
11
+
12
+ subject { ExceptionNotifier.notify_exception(StandardError.new, {}) }
13
+ it 'notify exception' do
14
+ expect(subject).to be_truthy
15
+ end
16
+
17
+ context 'Same error in 60 seconds' do
18
+ it '1st call, return true, 2nd call, return false' do
19
+ expect(subject).to be_truthy
20
+ expect(ExceptionNotifier.notify_exception(StandardError.new, {})).to be_falsy
21
+ end
22
+ end
23
+
24
+ context 'Same error after 60 seconds' do
25
+ it 'returns both true' do
26
+ ExceptionNotifier.notify_exception(StandardError.new, {})
27
+ Timecop.travel(Time.now + 60)
28
+ expect(subject).to be_truthy
29
+ end
30
+ end
31
+
32
+ context 'It cannot connect to Redis when setting params' do
33
+ before do
34
+ allow_any_instance_of(MockRedis).to receive(:set).and_raise(Redis::CannotConnectError)
35
+ end
36
+ it 'does not raise error' do
37
+ expect { subject }.not_to raise_error
38
+ end
39
+ end
40
+
41
+ context 'It cannot connect to Redis when getting params' do
42
+ before do
43
+ allow_any_instance_of(MockRedis).to receive(:get).and_raise(Redis::CannotConnectError)
44
+ end
45
+ it 'does not raise error' do
46
+ expect { subject }.not_to raise_error
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'exception_notification_moderate'
4
+ require 'timecop'
5
+ require 'pry-byebug'
6
+ require 'mock_redis'
7
+ require 'redis'
8
+
9
+ RSpec.configure do |config|
10
+ config.before :each do
11
+ redis_instance = MockRedis.new
12
+ allow(Redis).to receive(:new).and_return(redis_instance)
13
+ end
14
+ end
15
+
16
+
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: exception_notification_moderate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - ryonext
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: exception_notification
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: redis
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: timecop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-byebug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: mock_redis
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: When system raises same errors in short time, it blocks second and later
140
+ notifications
141
+ email:
142
+ - ryonext.s@gmail.com
143
+ executables: []
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".travis.yml"
150
+ - Gemfile
151
+ - LICENSE.txt
152
+ - README.md
153
+ - Rakefile
154
+ - exception_notification_moderate.gemspec
155
+ - lib/exception_notification_moderate.rb
156
+ - lib/exception_notification_moderate/exception_notifier.rb
157
+ - lib/exception_notification_moderate/version.rb
158
+ - spec/exception_notification_moderate_spec.rb
159
+ - spec/spec_helper.rb
160
+ homepage: http://github.com/ryonext/exception_notification_moderate
161
+ licenses:
162
+ - MIT
163
+ metadata: {}
164
+ post_install_message:
165
+ rdoc_options: []
166
+ require_paths:
167
+ - lib
168
+ required_ruby_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ required_rubygems_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ requirements: []
179
+ rubyforge_project:
180
+ rubygems_version: 2.2.2
181
+ signing_key:
182
+ specification_version: 4
183
+ summary: Notify same exception moderate.
184
+ test_files:
185
+ - spec/exception_notification_moderate_spec.rb
186
+ - spec/spec_helper.rb