faraday_middleware-circuit_breaker 0.3.0 → 0.5.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: 8deaaad1b7866b3bb93efe91ae63f492e446f382
4
- data.tar.gz: 4c79b86afe36d6ae42733d83ff21beac8365284c
2
+ SHA256:
3
+ metadata.gz: 005afebe17fb37c37d260ca776c581cc92cda261b7cafc241d6d4fb7ce39d860
4
+ data.tar.gz: e54b70864d6a74e8b13414c8af69dfb9ec5040a7c883663b088478ac523f19e3
5
5
  SHA512:
6
- metadata.gz: 0a1267f7b41141ff8f6c02dc96a5ae199d2ff5b2cc6b3e83e242d1eade766a0a24de721c3602525fd38867cf192df2ebb627fca73cd376d4d1b745ce31eb7387
7
- data.tar.gz: 2361860fcffd409f10db8ac07265116bedd52c0bc2947645ae4f00c2e4b802936679cbced2faf4f74a7c0d6b1688cf5737625df2910384658a227c5fb94ab2d8
6
+ metadata.gz: 81884db0ec02ed879a7e09d71b370a16a64a23daa183c9d9cfeb2db8650bc4f11339c7a83702f169e814ae048723caa2bb7ecf7c6426055f8a18ad9e4b978e49
7
+ data.tar.gz: d4f2942b93d59d50f9a994a9e86625a52307a38356b3e40fbf7454ca54c0774da2ca75667babab2fdd2950c71883ee457d49a622f892e50b1cb4fa5c2f3c2b0e
@@ -0,0 +1,50 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ - push
12
+
13
+ jobs:
14
+ test:
15
+
16
+ runs-on: ubuntu-latest
17
+
18
+ strategy:
19
+ matrix:
20
+ ruby:
21
+ - "2.4"
22
+ - "2.5"
23
+ - "2.6"
24
+ - "2.7"
25
+
26
+ name: ${{ matrix.ruby }}
27
+
28
+ steps:
29
+ - uses: actions/checkout@v2
30
+
31
+ - name: Set up Ruby
32
+ uses: ruby/setup-ruby@v1
33
+ with:
34
+ ruby-version: ${{ matrix.ruby }}
35
+
36
+ - name: Set up Cache
37
+ uses: actions/cache@v2
38
+ with:
39
+ path: vendor/bundle
40
+ key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
41
+ restore-keys: |
42
+ ${{ runner.os }}-gems-
43
+
44
+ - name: Install dependencies
45
+ run: |
46
+ bundle config path vendor/bundle
47
+ bundle install --jobs 4 --retry 3
48
+
49
+ - name: Run tests
50
+ run: bundle exec rake
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ .ruby-version
11
+ .rbenv-gemsets
data/CHANGELOG.md CHANGED
@@ -1,7 +1,41 @@
1
- # 0.3.0
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
2
3
 
3
- * Handles stoplight data store
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
4
6
 
5
- # 0.2.0
7
+ ## [Unreleased]
8
+
9
+ ## [0.5.0]
10
+
11
+ ### Changed
12
+
13
+ - Relaxed version requirement for Stoplight to include 3.0
14
+
15
+ ## [0.4.1]
16
+ ### Fixed
17
+
18
+ - Fixed `ArgumentError: Unknown option: data_store. Valid options are :timeout, threshold, fallback, notifiers, data_store,, error_handler`
19
+ due to an extra comma introduced in the valid option list.
20
+
21
+ ## [0.4.0]
22
+ ### Added
23
+
24
+ - Handle stoplight custom error handlers. Fixes https://github.com/textmaster/faraday_middleware-circuit_breaker/issues/3
25
+
26
+ ## [0.3.0]
27
+ ### Added
28
+ - Handles stoplight data store
29
+
30
+ ## [0.2.0]
31
+ ### Added
6
32
 
7
33
  * Introduces sentry/raven notifier
34
+
35
+ [Unreleased]: https://github.com/textmaster/faraday_middleware-circuit_breaker/compare/v0.5.0...HEAD
36
+ [0.5.0]: https://github.com/textmaster/faraday_middleware-circuit_breaker/compare/v0.4.1...v0.5.0
37
+ [0.4.1]: https://github.com/textmaster/faraday_middleware-circuit_breaker/compare/v0.4.0...v0.4.1
38
+ [0.4.0]: https://github.com/textmaster/faraday_middleware-circuit_breaker/compare/v0.3.0...v0.4.0
39
+ [0.3.0]: https://github.com/textmaster/faraday_middleware-circuit_breaker/compare/v0.2.0...v0.3.0
40
+ [0.2.0]: https://github.com/textmaster/faraday_middleware-circuit_breaker/compare/v0.1.0...v0.2.0
41
+ [0.0.1]: https://github.com/textmaster/faraday_middleware-circuit_breaker/releases/tag/v0.1.0
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in faraday_middleware-circuit_breaker.gemspec
4
4
  gemspec
5
+
6
+ gem "rake", "~> 12.0"
data/README.md CHANGED
@@ -57,7 +57,7 @@ The default is `3` times.
57
57
 
58
58
  ### Custom fallback
59
59
 
60
- On a failure, middlware will render an empty `503` http response by default. You can customize the fallback response:
60
+ On a failure, middleware will render an empty `503` http response by default. You can customize the fallback response:
61
61
 
62
62
  ```ruby
63
63
  Faraday.new(url: 'http://foo.com') do |c|
@@ -88,6 +88,40 @@ Whatever you chose, your method should return a valid faraday response. For exam
88
88
  proc { Faraday::Response.new(status: 503, response_headers: {}) }
89
89
  ```
90
90
 
91
+ ### Custom error handling
92
+
93
+ In some situations, it might required to allow for particular error types to be exempt from tripping the circuit breaker
94
+ (like regular 403 or 401 HTTP responses, which aren't really out-of-the-ordinary conditions that should trip the circuit breaker).
95
+ The underlying stoplight gem supports [custom error handling](https://github.com/orgsync/stoplight#custom-errors),
96
+ The `error_handler` option allows you to add your own customer error handler behavior:
97
+
98
+ ```ruby
99
+ Faraday.new(url: 'http://foo.com') do |c|
100
+ c.use :circuit_breaker, error_handler: ->(exception, handler) { # do something }
101
+ end
102
+ ```
103
+
104
+ Middleware will try to call the `call` method on `error_handler` passing 2 arguments:
105
+
106
+ - `exception` -- the exception raised that triggered the circuit breaker
107
+ - `handler` -- the current error handler `Proc` that would be in charge of handling the `exception` if no `error_handler` option was passed
108
+
109
+ You can pass a method to be eager called like this (with a handler that exempts `ArgumentError` from tripping the circuit):
110
+
111
+ ```ruby
112
+ Faraday.new(url: 'http://foo.com') do |c|
113
+ c.use :circuit_breaker, error_handler: method(:foo)
114
+ end
115
+
116
+ def foo(exception, handler)
117
+ raise exception if exception.is_a?(ArgumentError)
118
+ handler.call(exception)
119
+ end
120
+ ```
121
+
122
+ NOTE: It is most always a good idea to call the original `handler` with the exception that was passed in at the end of your
123
+ handler. (By default, the `error_handler` will just be [`Stoplight::Default::ERROR_HANDLER`](https://github.com/orgsync/stoplight/blob/master/lib/stoplight/default.rb#L9))
124
+
91
125
  ### Notifiers
92
126
 
93
127
  Middleware send notifications to standard error by default. You can customize the receivers.
data/Rakefile CHANGED
@@ -3,4 +3,4 @@ require "rspec/core/rake_task"
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
@@ -1,7 +1,4 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'faraday_middleware/circuit_breaker/version'
1
+ require_relative 'lib/faraday_middleware/circuit_breaker/version'
5
2
 
6
3
  Gem::Specification.new do |spec|
7
4
  spec.name = "faraday_middleware-circuit_breaker"
@@ -13,16 +10,25 @@ Gem::Specification.new do |spec|
13
10
  spec.description = %q{A Faraday Middleware to handle spotty web services.}
14
11
  spec.homepage = "https://github.com/textmaster/faraday_middleware-circuit_breaker"
15
12
  spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
16
14
 
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = "bin"
19
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/textmaster/faraday_middleware-circuit_breaker"
19
+ spec.metadata["changelog_uri"] = "https://github.com/textmaster/faraday_middleware-circuit_breaker/blob/master/CHANGELOG.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
28
  spec.require_paths = ["lib"]
21
29
 
22
- spec.add_dependency 'faraday', '~> 0.9'
23
- spec.add_dependency 'stoplight', '~> 2.1'
30
+ spec.add_dependency 'faraday', '>= 0.9', '< 2.0'
31
+ spec.add_dependency 'stoplight', '>= 2.1', '< 4.0'
24
32
 
25
- spec.add_development_dependency 'bundler', '~> 1.10'
26
- spec.add_development_dependency 'rake', '~> 11.2'
27
33
  spec.add_development_dependency 'rspec'
28
34
  end
@@ -17,12 +17,14 @@ module FaradayMiddleware
17
17
  end
18
18
 
19
19
  def call(env)
20
- Stoplight(env.url.to_s) do
20
+ base_url = URI.join(env.url, '/')
21
+ Stoplight(base_url.to_s) do
21
22
  @app.call(env)
22
23
  end
23
24
  .with_cool_off_time(option_set.timeout)
24
25
  .with_threshold(option_set.threshold)
25
26
  .with_fallback { |e| option_set.fallback.call(env, e) }
27
+ .with_error_handler { |err, handler| option_set.error_handler.call(err, handler) }
26
28
  .run
27
29
  end
28
30
 
@@ -6,9 +6,9 @@ module FaradayMiddleware
6
6
  module CircuitBreaker
7
7
  class OptionSet
8
8
 
9
- VALID_OPTIONS = %w(timeout threshold fallback notifiers data_store)
9
+ VALID_OPTIONS = %w(timeout threshold fallback notifiers data_store error_handler)
10
10
 
11
- attr_accessor :timeout, :threshold, :fallback, :notifiers, :data_store
11
+ attr_accessor :timeout, :threshold, :fallback, :notifiers, :data_store, :error_handler
12
12
 
13
13
  def initialize(options = {})
14
14
  @timeout = options[:timeout] || 60.0
@@ -16,6 +16,7 @@ module FaradayMiddleware
16
16
  @fallback = options[:fallback] || proc { Faraday::Response.new(status: 503, response_headers: {}) }
17
17
  @notifiers = options[:notifiers] || {}
18
18
  @data_store = options[:data_store] || proc { Stoplight::Light.default_data_store }
19
+ @error_handler = options[:error_handler] || Stoplight::Default::ERROR_HANDLER
19
20
  end
20
21
 
21
22
  def self.validate!(options)
@@ -1,5 +1,5 @@
1
1
  module FaradayMiddleware
2
2
  module CircuitBreaker
3
- VERSION = "0.3.0"
3
+ VERSION = "0.5.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,71 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday_middleware-circuit_breaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre-Louis Gottfrois
8
- autorequire:
9
- bindir: bin
8
+ autorequire:
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-09 00:00:00.000000000 Z
11
+ date: 2022-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.9'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '0.9'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: stoplight
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - "~>"
37
+ - - ">="
32
38
  - !ruby/object:Gem::Version
33
39
  version: '2.1'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '4.0'
34
43
  type: :runtime
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
38
- - - "~>"
47
+ - - ">="
39
48
  - !ruby/object:Gem::Version
40
49
  version: '2.1'
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
50
+ - - "<"
46
51
  - !ruby/object:Gem::Version
47
- version: '1.10'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.10'
55
- - !ruby/object:Gem::Dependency
56
- name: rake
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '11.2'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '11.2'
52
+ version: '4.0'
69
53
  - !ruby/object:Gem::Dependency
70
54
  name: rspec
71
55
  requirement: !ruby/object:Gem::Requirement
@@ -83,12 +67,11 @@ dependencies:
83
67
  description: A Faraday Middleware to handle spotty web services.
84
68
  email:
85
69
  - pierre-louis@textmaster.com
86
- executables:
87
- - console
88
- - setup
70
+ executables: []
89
71
  extensions: []
90
72
  extra_rdoc_files: []
91
73
  files:
74
+ - ".github/workflows/ruby.yml"
92
75
  - ".gitignore"
93
76
  - ".rspec"
94
77
  - ".travis.yml"
@@ -107,8 +90,12 @@ files:
107
90
  homepage: https://github.com/textmaster/faraday_middleware-circuit_breaker
108
91
  licenses:
109
92
  - MIT
110
- metadata: {}
111
- post_install_message:
93
+ metadata:
94
+ allowed_push_host: https://rubygems.org
95
+ homepage_uri: https://github.com/textmaster/faraday_middleware-circuit_breaker
96
+ source_code_uri: https://github.com/textmaster/faraday_middleware-circuit_breaker
97
+ changelog_uri: https://github.com/textmaster/faraday_middleware-circuit_breaker/blob/master/CHANGELOG.md
98
+ post_install_message:
112
99
  rdoc_options: []
113
100
  require_paths:
114
101
  - lib
@@ -116,16 +103,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
103
  requirements:
117
104
  - - ">="
118
105
  - !ruby/object:Gem::Version
119
- version: '0'
106
+ version: 2.4.0
120
107
  required_rubygems_version: !ruby/object:Gem::Requirement
121
108
  requirements:
122
109
  - - ">="
123
110
  - !ruby/object:Gem::Version
124
111
  version: '0'
125
112
  requirements: []
126
- rubyforge_project:
127
- rubygems_version: 2.6.13
128
- signing_key:
113
+ rubygems_version: 3.0.3
114
+ signing_key:
129
115
  specification_version: 4
130
116
  summary: Middleware to apply circuit breaker pattern.
131
117
  test_files: []