breakers 0.2.1 → 0.4.0

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
- SHA1:
3
- metadata.gz: 35c7aacf61c91cf32f46b61946acb6f80d0b00fc
4
- data.tar.gz: 4d62beb0e55e286b22ae035f2ac3a8f390a271fd
2
+ SHA256:
3
+ metadata.gz: f3f0fe57f169c943767204654e3a06cc0bfa1b5d94d5526b2b9a17277b7dddca
4
+ data.tar.gz: 2c2d30d44317fa7ebeb595b6dee476327b93a9d34466de1c25136c48b3201505
5
5
  SHA512:
6
- metadata.gz: 2cc042397050ea304a6632a7f758e9fe2f3efdabc48843759366f6f953a50762ecd432be06846d211b2e537b7e283730772f021febc866d85447166e32444323
7
- data.tar.gz: 9358d0bbf12c1b5b378ecaa2b94584e775887e746958ef0405d176daf5a207ba780a108428ab7f49c6fa92eebe6174e90ad6668004b085de0b473fc4a6f90c77
6
+ metadata.gz: 97f7d582d247487f891990c0283b191fb3a34f3340bcb61d36dd3bb999a8cb0831d920dee3f172b250a2e2405ac323a7cadf9df6f041f2ec85a309c185b1554f
7
+ data.tar.gz: c0a1271baf89a686198968c6153c2e6f3eee5eb044faef715623d389bc6d640290ca633ef55d096562ac20dad79cf827e0520bb167fdaf3b9110c8413afc29e4
@@ -2,6 +2,8 @@ AllCops:
2
2
  TargetRubyVersion: 2.3
3
3
  Include:
4
4
  - 'Rakefile'
5
+ Exclude:
6
+ - Gemfile
5
7
 
6
8
  Metrics/LineLength:
7
9
  Max: 140
@@ -22,6 +24,9 @@ Metrics/ClassLength:
22
24
  Metrics/MethodLength:
23
25
  Max: 50
24
26
 
27
+ Metrics/BlockLength:
28
+ Max: 500
29
+
25
30
  Metrics/AbcSize:
26
31
  Max: 75
27
32
 
@@ -98,7 +103,7 @@ Style/GuardClause:
98
103
  Style/Next:
99
104
  Enabled: false
100
105
 
101
- Style/IndentArray:
106
+ Layout/IndentArray:
102
107
  EnforcedStyle: consistent
103
108
 
104
109
  # This forces you to change simple if/unless blocks to the conditional form like: `return 2 if badness`.
@@ -149,7 +154,7 @@ Style/WordArray:
149
154
 
150
155
  # Some people really like to put lines at the beginning and end of class bodies, while other people
151
156
  # really don't. It doesn't really seem to matter.
152
- Style/EmptyLinesAroundClassBody:
157
+ Layout/EmptyLinesAroundClassBody:
153
158
  Enabled: false
154
159
 
155
160
  # This forces you to put a comment like this at the top of every single file:
@@ -164,10 +169,10 @@ Style/Lambda:
164
169
  Enabled: false
165
170
 
166
171
  # Force indentation for milti-line expressions and method calls
167
- Style/MultilineOperationIndentation:
172
+ Layout/MultilineOperationIndentation:
168
173
  EnforcedStyle: indented
169
174
 
170
- Style/MultilineMethodCallIndentation:
175
+ Layout/MultilineMethodCallIndentation:
171
176
  EnforcedStyle: indented
172
177
 
173
178
  # This disallows the use of $1, $2 from regular expressions, which seems to make no sense whatsoever
@@ -198,7 +203,7 @@ Style/ZeroLengthPredicate:
198
203
  # ...
199
204
  # end
200
205
  Lint/EndAlignment:
201
- AlignWith: variable
206
+ EnforcedStyleAlignWith: variable
202
207
 
203
208
  # This cop will require you to replace or prefix method arguments that go unused with underscores. The problem
204
209
  # is that while seeming to solve no problem this could easily cause issues where someone editing the code to
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'breakers/version'
@@ -21,7 +22,7 @@ Gem::Specification.new do |spec|
21
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
23
  spec.require_paths = ['lib']
23
24
 
24
- spec.add_dependency 'faraday', ['>= 0.7.4', '< 0.10']
25
+ spec.add_dependency 'faraday', ['>= 0.7.4', '< 0.18']
25
26
  spec.add_dependency 'multi_json', '~> 1.0'
26
27
 
27
28
  spec.add_development_dependency 'bundler', '~> 1.0'
@@ -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)
@@ -35,6 +35,9 @@ module Breakers
35
35
  protected
36
36
 
37
37
  def outage_response(outage:, service:)
38
+ Breakers.client.plugins.each do |plugin|
39
+ plugin.on_skipped_request(service) if plugin.respond_to?(:on_skipped_request)
40
+ end
38
41
  if Breakers.outage_response[:type] == :status_code
39
42
  Faraday::Response.new.tap do |response|
40
43
  response.finish(
@@ -49,7 +52,9 @@ module Breakers
49
52
  end
50
53
 
51
54
  def handle_request(service:, request_env:, current_outage: nil)
55
+ start_time = Time.now
52
56
  return @app.call(request_env).on_complete do |response_env|
57
+ response_env[:duration] = (Time.now - start_time) * 1000
53
58
  if response_env.status >= 500
54
59
  handle_error(
55
60
  service: service,
@@ -67,8 +72,17 @@ module Breakers
67
72
  end
68
73
  end
69
74
  end
75
+ rescue Faraday::TimeoutError, Faraday::ConnectionFailed => e
76
+ handle_error(
77
+ service: service,
78
+ request_env: request_env,
79
+ response_env: nil,
80
+ error: "#{e.class.name} - #{e.message}",
81
+ current_outage: current_outage
82
+ )
83
+ raise
70
84
  rescue => e
71
- unless e.is_a?(Breakers::OutageException)
85
+ if service.exception_represents_server_error?(e)
72
86
  handle_error(
73
87
  service: service,
74
88
  request_env: request_env,
@@ -1,3 +1,3 @@
1
1
  module Breakers
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.4.0'.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.1
4
+ version: 0.4.0
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-26 00:00:00.000000000 Z
11
+ date: 2020-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 0.7.4
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '0.10'
22
+ version: '0.18'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: 0.7.4
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '0.10'
32
+ version: '0.18'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: multi_json
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -215,10 +215,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
215
  - !ruby/object:Gem::Version
216
216
  version: '0'
217
217
  requirements: []
218
- rubyforge_project:
219
- rubygems_version: 2.5.1
218
+ rubygems_version: 3.1.4
220
219
  signing_key:
221
220
  specification_version: 4
222
221
  summary: Handle outages to backend systems with a Faraday middleware
223
222
  test_files: []
224
- has_rdoc: