airbrake_proxy 0.1.1 → 0.1.2

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
2
  SHA1:
3
- metadata.gz: dcbb01d6954be318e40af6ba4fad1ae5d2b85e30
4
- data.tar.gz: b3374ae338faddcaf597ec2c2e46564d6261ba14
3
+ metadata.gz: 3d9a063f02b1305386b9dce0b93f6838d7597ad0
4
+ data.tar.gz: 5a954ef60b31a332c9e4f63ac226510ec416f3df
5
5
  SHA512:
6
- metadata.gz: 4e2a33d568fa85a3fdc3e9d50c39c93191bb1f38bfd082c7f1cf2163b349ec87289c43b0e8b8f56c3dffb66613d57aeb6f1e61186fdf0c33e07152b88d2d7170
7
- data.tar.gz: 1de9bca1c47aaf21c67fae25c75df91f174222b16caf7a99178069e87d8a361b6a74c154f79f42b3b46707a74489e5c984c0d20ea7e4c91dd7c47ab67744e78b
6
+ metadata.gz: 886e7db68b0bd006f60eb1620fc7557ba8d4dfd441b92eca8cebdfbe8b79ec6e97151b1a1bd2e07e9c10a3f0af3cdb39a7c138c525cbdebb57a3d21e846dd723
7
+ data.tar.gz: 221b42104c51836189ef830e1600dbd9983c564ab5b6b3eec7efd4360d216820cdf922822a5cc046060297a2ebab0a8188abf0e07df4a10bea0d49da36e9fb67
@@ -0,0 +1,2 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
data/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  [![Build Status](https://travis-ci.org/FinalCAD/airbrake_proxy.png?branch=master)](https://travis-ci.org/FinalCAD/airbrake_proxy) (Travis CI)
10
10
 
11
- [![Coverage Status](https://coveralls.io/repos/FinalCAD/airbrake_proxy/badge.png)](https://coveralls.io/r/FinalCAD/airbrake_proxy)
11
+ [![Coverage Status](https://coveralls.io/repos/github/FinalCAD/airbrake_proxy/badge.svg?branch=master)](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
 
@@ -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(exception)
66
- "#{KEY_PREFIX}#{(exception&.message || exception.inspect).parameterize}"
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
- unless RedisProxy.exists(key)
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
@@ -1,3 +1,3 @@
1
1
  module AirbrakeProxy
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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.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