airbrake_proxy 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/README.md +24 -1
- data/lib/airbrake_proxy.rb +18 -8
- data/lib/airbrake_proxy/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d9a063f02b1305386b9dce0b93f6838d7597ad0
|
4
|
+
data.tar.gz: 5a954ef60b31a332c9e4f63ac226510ec416f3df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 886e7db68b0bd006f60eb1620fc7557ba8d4dfd441b92eca8cebdfbe8b79ec6e97151b1a1bd2e07e9c10a3f0af3cdb39a7c138c525cbdebb57a3d21e846dd723
|
7
|
+
data.tar.gz: 221b42104c51836189ef830e1600dbd9983c564ab5b6b3eec7efd4360d216820cdf922822a5cc046060297a2ebab0a8188abf0e07df4a10bea0d49da36e9fb67
|
data/.rubocop.yml
ADDED
data/README.md
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
[](https://travis-ci.org/FinalCAD/airbrake_proxy) (Travis CI)
|
10
10
|
|
11
|
-
[](https://coveralls.io/github/FinalCAD/airbrake_proxy?branch=master)
|
12
12
|
|
13
13
|
Basic Circuit Breaker to attempt not reach Airbrake limit for the same exception
|
14
14
|
|
@@ -20,6 +20,28 @@ Add this line to your application's Gemfile:
|
|
20
20
|
gem 'airbrake_proxy'
|
21
21
|
```
|
22
22
|
|
23
|
+
Please add a config file on your project.
|
24
|
+
|
25
|
+
Rails sample
|
26
|
+
|
27
|
+
`config/initializers/airbrake_proxy.rb`
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
AirbrakeProxy.configure do |conf|
|
31
|
+
conf.redis = Resque.redis
|
32
|
+
conf.logger = Rails.logger
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
in `spec/spec_helper.rb` or `spec/rails_helper.rb`
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
AirbrakeProxy.configure do |conf|
|
40
|
+
conf.redis = MockRedis.new
|
41
|
+
conf.logger = Logger.new($stderr)
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
23
45
|
And then execute:
|
24
46
|
|
25
47
|
$ bundle
|
@@ -30,6 +52,7 @@ Or install it yourself as:
|
|
30
52
|
|
31
53
|
## Usage
|
32
54
|
|
55
|
+
Simply use `AirbrakeProxy.notify(exception)` in your code instead of `Airbrake.notify exception`
|
33
56
|
|
34
57
|
## Development
|
35
58
|
|
data/lib/airbrake_proxy.rb
CHANGED
@@ -59,24 +59,34 @@ module AirbrakeProxy
|
|
59
59
|
unless authorized_to_notify?(redis_key)
|
60
60
|
raise TooManyNotification.new("#{redis_key} was notified too many times")
|
61
61
|
end
|
62
|
+
|
62
63
|
yield
|
63
64
|
end
|
64
65
|
|
65
|
-
def key(
|
66
|
-
|
66
|
+
def key(exception_or_message)
|
67
|
+
msg = case exception_or_message
|
68
|
+
when String
|
69
|
+
exception_or_message
|
70
|
+
when StandardError, Exception
|
71
|
+
exception_or_message.message
|
72
|
+
else
|
73
|
+
exception_or_message.to_s
|
74
|
+
end
|
75
|
+
"#{KEY_PREFIX}#{msg.parameterize}"
|
67
76
|
end
|
68
77
|
|
69
78
|
def authorized_to_notify?(key)
|
70
79
|
return false if RedisProxy.get(key).to_i >= THRESHOLD # We won't hint Redis#incr(key) to not reset timelife of key
|
71
|
-
mark_as_notify(key) # return value is a true predicate
|
80
|
+
mark_as_notify!(key) # return value is a true predicate
|
81
|
+
true
|
72
82
|
end
|
73
83
|
|
74
|
-
def mark_as_notify(key)
|
75
|
-
|
76
|
-
RedisProxy.set(key, 0)
|
77
|
-
RedisProxy.expire(key, T_5_HOURS)
|
78
|
-
end
|
84
|
+
def mark_as_notify!(key)
|
85
|
+
RedisProxy.multi
|
79
86
|
RedisProxy.incr(key)
|
87
|
+
RedisProxy.expire(key, T_1_HOUR)
|
88
|
+
RedisProxy.exec
|
89
|
+
nil
|
80
90
|
end
|
81
91
|
|
82
92
|
private
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: airbrake_proxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel AZEMAR
|
@@ -118,6 +118,7 @@ extra_rdoc_files: []
|
|
118
118
|
files:
|
119
119
|
- ".gitignore"
|
120
120
|
- ".rspec"
|
121
|
+
- ".rubocop.yml"
|
121
122
|
- ".travis.yml"
|
122
123
|
- CHANGELOG.md
|
123
124
|
- CODE_OF_CONDUCT.md
|