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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e6817087ef7b241395a0788e84a0ee14cfb476f
4
- data.tar.gz: 95130c9e75c4915a1b6d6fd88bcc8ee8ae7e1564
3
+ metadata.gz: 3f5942c1ecd3fe9ca40c1f5add1c5c90d7ef79f4
4
+ data.tar.gz: fc3d54d89f980967bfce174e5bf82684b7f62fd7
5
5
  SHA512:
6
- metadata.gz: df1d03686061dea6bc19d266463d7d884e5d2610740b6381cdd25c90e48beace78d59f9f7590c275b696d7068d2156e04dd7b5ee6b5bb326d51150b966a27c96
7
- data.tar.gz: 44c580e0f38c489e474fbe8c88ab79a1b2ad0d259973964765c296f0a9e73b08519248a6c134d77e3462e8c1e5fa03060cb6c04288a6ce9abbb6ab802fc8cec2
6
+ metadata.gz: 39a7a8e80ba0f3c990a07cbffe80f5b8804deb770384dee39b3d28b3637a798bc3111add4b90c425742d0e2c74fac0b4786fcdfca3773e585d4f534faedf72fe
7
+ data.tar.gz: 27c9ded47ee71b42a53b67c60dff4c40256d96fb6923efcd133b09370f43b229f46c05098b664300482a6e2afaf8e7e6dffd9fc869c3ee09d3b386bfad1812ec
@@ -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
- unless e.is_a?(Breakers::OutageException)
82
+ if service.exception_represents_server_error?(e)
74
83
  handle_error(
75
84
  service: service,
76
85
  request_env: request_env,
@@ -1,3 +1,3 @@
1
1
  module Breakers
2
- VERSION = '0.2.2'.freeze
2
+ VERSION = '0.2.3'.freeze
3
3
  end
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.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-28 00:00:00.000000000 Z
11
+ date: 2016-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday