gruf-circuit-breaker 0.1.3 → 1.0.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
2
  SHA1:
3
- metadata.gz: b16d5d48832a9bb1a168222fdac0de751f517556
4
- data.tar.gz: a055a5833e82e781f0f9654325d6ca61bc74fb2e
3
+ metadata.gz: b812cddba85e6ed5a9a2efa6624b33c71b87b97d
4
+ data.tar.gz: c841e828ceefd724ca89fb7faeb4f218e7c5e850
5
5
  SHA512:
6
- metadata.gz: 3e85e39daa737aa178b120d3a36f8393f3ac2082422399d73d0ea469af99a903f0bdac1bc2b9e1d5bddaa678979fec3f10ede2c1a351a3952517e2b24da7544d
7
- data.tar.gz: c9ba632395b6fc61cfd7374910c8a4902e115e02cb7b37a3435417db4eb795cc2abe22d4216c65d51668bb26a01f58623dff45cee685903abc375fca43a8b276
6
+ metadata.gz: 3849d1ebcc7fd3569c18a836f2e1ccf25e8c4f0fc0ef95ba14ce375047a1aa4f36b9f387dc1c01b6ecdf9d23628083bbf1ccc82c5aba4b887dc2ed138d8f10f0
7
+ data.tar.gz: e4a2f4d405356141ec6c96c17a3839931a161b2e0ba23a566626b5c6f137d132c01bfe00caf193c035b96f37339da6c63b51f1b1b4da4b4d2ab31f1fabde2ce2
@@ -1,5 +1,9 @@
1
1
  Changelog for the gruf-circuit-breaker gem.
2
2
 
3
+ h3. 1.0.0
4
+
5
+ - gruf 2.0 support
6
+
3
7
  h3. 0.1.3
4
8
 
5
9
  - Add rubocop to test suite
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # gruf-circuit-breaker - Circuit Breaker for gruf
2
2
 
3
- [![Build Status](https://travis-ci.org/bigcommerce/gruf-circuit-breaker.svg?branch=master)](https://travis-ci.org/bigcommerce/gruf-circuit-breaker)
3
+ [![Build Status](https://travis-ci.org/bigcommerce/gruf-circuit-breaker.svg?branch=master)](https://travis-ci.org/bigcommerce/gruf-circuit-breaker) [![Gem Version](https://badge.fury.io/rb/gruf-circuit-breaker.svg)](https://badge.fury.io/rb/gruf-circuit-breaker) [![Inline docs](http://inch-ci.org/github/bigcommerce/gruf-circuit-breaker.svg?branch=master)](http://inch-ci.org/github/bigcommerce/gruf-circuit-breaker)
4
4
 
5
- Adds circuit breaker support for [gruf](https://github.com/bigcommerce/gruf) 1.0.0 or later.
5
+ Adds circuit breaker support for [gruf](https://github.com/bigcommerce/gruf) 2.0.0 or later.
6
6
 
7
7
  This uses the wonderful [stoplight](https://github.com/orgsync/stoplight) gem for handling
8
8
  the internals of circuit breaking.
@@ -26,7 +26,7 @@ You can further customize the tracing of gruf services via the configuration:
26
26
 
27
27
  ```ruby
28
28
  Gruf.configure do |c|
29
- c.hook_options[:circuit_breaker] = {
29
+ c.interceptors.use(Gruf::CircuitBreaker::Interceptor, {
30
30
  # set cool-off time in seconds (defaults to 60)
31
31
  cool_off_time: 15,
32
32
  # set threshold count to 2
@@ -35,7 +35,7 @@ Gruf.configure do |c|
35
35
  failure_statuses: [GRPC::Internal, GRPC::Unknown, GRPC::Aborted],
36
36
  # use a redis instance for the stoplight data storage
37
37
  redis: Redis.new
38
- }
38
+ })
39
39
  end
40
40
  ```
41
41
 
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
2
  #
4
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
@@ -16,9 +15,15 @@
16
15
  #
17
16
  require 'stoplight'
18
17
  require_relative 'circuit_breaker/version'
19
- require_relative 'circuit_breaker/hook'
18
+ require_relative 'circuit_breaker/interceptor'
20
19
 
20
+ ##
21
+ # Base gruf module
22
+ #
21
23
  module Gruf
24
+ ##
25
+ # Base CircuitBreaker module
26
+ #
22
27
  module CircuitBreaker
23
28
  end
24
29
  end
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
2
  #
4
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
@@ -16,26 +15,25 @@
16
15
  #
17
16
  module Gruf
18
17
  module CircuitBreaker
19
- class Hook < Gruf::Hooks::Base
20
-
18
+ ##
19
+ # Intercepts gruf requests and adds a circuit breaker implementation
20
+ #
21
+ class Interceptor < Gruf::Interceptors::ServerInterceptor
21
22
  ##
22
23
  # Sets up the stoplight gem
23
24
  #
24
- def setup
25
+ def initialize(request, error, options = {})
25
26
  redis = options.fetch(:redis, nil)
26
27
  Stoplight::Light.default_data_store = Stoplight::DataStore::Redis.new(redis) if redis && redis.is_a?(Redis)
28
+ super(request, error, options)
27
29
  end
28
30
 
29
31
  ##
30
32
  # Handle the gruf around hook
31
33
  #
32
- # @param [Symbol] call_signature
33
- # @param [Object] request
34
- # @param [GRPC::ActiveCall] active_call
35
- #
36
- def around(call_signature, request, active_call, &block)
37
- light = Stoplight(method_key(call_signature)) do
38
- block.call(call_signature, request, active_call)
34
+ def call
35
+ light = Stoplight(request.method_key) do
36
+ yield
39
37
  end
40
38
  light.with_cool_off_time(options.fetch(:cool_off_time, 60))
41
39
  light.with_error_handler do |error, handle|
@@ -45,24 +43,17 @@ module Gruf
45
43
  raise error unless failure_statuses.include?(error.class)
46
44
  handle.call(error)
47
45
  end
48
- light.with_threshold(options.fetch(:threshold, 1)) if options.fetch(:threshold, false)
46
+ light.with_threshold(threshold) if threshold > 0
49
47
  light.run
50
48
  end
51
49
 
52
50
  private
53
51
 
54
52
  ##
55
- # @return [String]
56
- #
57
- def method_key(call_signature)
58
- "#{service_key}.#{call_signature.to_s.gsub('_without_intercept', '')}"
59
- end
60
-
61
- ##
62
- # @return [String]
53
+ # @return [Integer]
63
54
  #
64
- def service_key
65
- service.class.name.underscore.tr('/', '.')
55
+ def threshold
56
+ options.fetch(:threshold, 0).to_i
66
57
  end
67
58
 
68
59
  ##
@@ -71,13 +62,6 @@ module Gruf
71
62
  def failure_statuses
72
63
  options.fetch(:failure_statuses, [GRPC::Internal, GRPC::Unknown])
73
64
  end
74
-
75
- ##
76
- # @return [Hash]
77
- #
78
- def options
79
- @options.fetch(:circuit_breaker, {})
80
- end
81
65
  end
82
66
  end
83
67
  end
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
2
  #
4
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
@@ -16,6 +15,6 @@
16
15
  #
17
16
  module Gruf
18
17
  module CircuitBreaker
19
- VERSION = '0.1.3'.freeze
18
+ VERSION = '1.0.0'.freeze
20
19
  end
21
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gruf-circuit-breaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaun McCormick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-12 00:00:00.000000000 Z
11
+ date: 2017-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -92,7 +92,7 @@ files:
92
92
  - README.md
93
93
  - gruf-circuit-breaker.gemspec
94
94
  - lib/gruf/circuit_breaker.rb
95
- - lib/gruf/circuit_breaker/hook.rb
95
+ - lib/gruf/circuit_breaker/interceptor.rb
96
96
  - lib/gruf/circuit_breaker/version.rb
97
97
  homepage: https://github.com/bigcommerce/gruf-circuit-breaker
98
98
  licenses:
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  version: '0'
115
115
  requirements: []
116
116
  rubyforge_project:
117
- rubygems_version: 2.6.12
117
+ rubygems_version: 2.6.13
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: Plugin for implementing the circuit breaker pattern for gruf gRPC requests