breakers 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/breakers/service.rb +8 -0
- data/lib/breakers/uptime_middleware.rb +10 -1
- data/lib/breakers/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f5942c1ecd3fe9ca40c1f5add1c5c90d7ef79f4
|
4
|
+
data.tar.gz: fc3d54d89f980967bfce174e5bf82684b7f62fd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39a7a8e80ba0f3c990a07cbffe80f5b8804deb770384dee39b3d28b3637a798bc3111add4b90c425742d0e2c74fac0b4786fcdfca3773e585d4f534faedf72fe
|
7
|
+
data.tar.gz: 27c9ded47ee71b42a53b67c60dff4c40256d96fb6923efcd133b09370f43b229f46c05098b664300482a6e2afaf8e7e6dffd9fc869c3ee09d3b386bfad1812ec
|
data/lib/breakers/service.rb
CHANGED
@@ -17,6 +17,7 @@ module Breakers
|
|
17
17
|
# @option opts [Integer] :seconds_before_retry The number of seconds to wait after an outage begins before testing with a new request
|
18
18
|
# @option opts [Integer] :error_threshold The percentage of errors over the last two minutes that indicates an outage
|
19
19
|
# @option opts [Integer] :data_retention_seconds The number of seconds to retain success and error data in Redis
|
20
|
+
# @option opts [Proc] :exception_handler A proc taking an exception and returns true if it represents an error on the service
|
20
21
|
def initialize(opts)
|
21
22
|
@configuration = DEFAULT_OPTS.merge(opts)
|
22
23
|
end
|
@@ -43,6 +44,13 @@ module Breakers
|
|
43
44
|
@configuration[:seconds_before_retry]
|
44
45
|
end
|
45
46
|
|
47
|
+
# Returns true if a given exception represents an error with the service
|
48
|
+
#
|
49
|
+
# @return [Boolean] is it an error?
|
50
|
+
def exception_represents_server_error?(exception)
|
51
|
+
@configuration[:exception_handler]&.call(exception)
|
52
|
+
end
|
53
|
+
|
46
54
|
# Indicate that an error has occurred and potentially create an outage
|
47
55
|
def add_error
|
48
56
|
increment_key(key: errors_key)
|
@@ -69,8 +69,17 @@ module Breakers
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
72
|
+
rescue Faraday::Error::TimeoutError => e
|
73
|
+
handle_error(
|
74
|
+
service: service,
|
75
|
+
request_env: request_env,
|
76
|
+
response_env: nil,
|
77
|
+
error: "#{e.class.name} - #{e.message}",
|
78
|
+
current_outage: current_outage
|
79
|
+
)
|
80
|
+
raise
|
72
81
|
rescue => e
|
73
|
-
|
82
|
+
if service.exception_represents_server_error?(e)
|
74
83
|
handle_error(
|
75
84
|
service: service,
|
76
85
|
request_env: request_env,
|
data/lib/breakers/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: breakers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aubrey Holland
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10
|
11
|
+
date: 2016-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|