rcb 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -4
- data/lib/rcb/instance.rb +11 -26
- data/lib/rcb/state.rb +1 -1
- data/lib/rcb/state_store.rb +22 -0
- data/lib/rcb.rb +2 -2
- data/rcb.gemspec +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51b22ffe23d17fa75f779c6c40bc810ff5d68e89a90a7ac3ff2f970f2974264e
|
4
|
+
data.tar.gz: 4741eaa76f5f29794c0dcdd83070cbec2c4544aa07ca8177a3af52fd8de5f221
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12426ff000383b3aaf8cfa02aac6ab5b71b903c0636ac8c9d4a2169306c2a113eb4445585fa7565c629a26a541fb0d02e0d12885a1b6e8be03bac05a266797c1
|
7
|
+
data.tar.gz: eec801904cd87bcaae6b8b58e3e86c40339587e127ba16b3f79f725ec3755376a338ceee6acd10b28c638c36ea8ce850ae7e2f524d1811b73680de18e34f2540
|
data/README.md
CHANGED
@@ -45,20 +45,25 @@ Add configuration with specifying `tag` like:
|
|
45
45
|
|
46
46
|
```ruby
|
47
47
|
Rcb.configure('fooo.com') do |config|
|
48
|
-
config.max_failure_count 1
|
48
|
+
config.open_condition.max_failure_count 1
|
49
|
+
config.open_condition.window_msec 1000
|
49
50
|
config.reset_timeout_msec 100
|
50
51
|
end
|
51
52
|
|
52
53
|
Rcb.configure('hoge.com') do |config|
|
53
|
-
config.max_failure_count 3
|
54
|
+
config.open_condition.max_failure_count 3
|
55
|
+
config.open_condition.window_msec 3000
|
54
56
|
config.reset_timeout_msec 300
|
55
57
|
end
|
56
58
|
```
|
57
59
|
|
58
60
|
These configurations are for both 'fooo.com' and 'hoge.com'.
|
59
61
|
|
60
|
-
- `
|
61
|
-
-
|
62
|
+
- `open_condition`: a condition to decide whether trip to open from close
|
63
|
+
- `max_failure_count`: a threshold for execution failures.
|
64
|
+
- if the breaker reaches the given `max_failure_count`, enters Open state from Close
|
65
|
+
- `window_msec`: a window time(milliseconds) for failures
|
66
|
+
- if the breaker catched failures more than `window_msec` before, they are discarded
|
62
67
|
- `reset_timeout_msec`: milliseconds to wait for next try
|
63
68
|
- after the given `reset_timeout_msec`, the circuit breaker enters a Half-Open state from Open
|
64
69
|
|
data/lib/rcb/instance.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rstructural'
|
2
2
|
require_relative './state'
|
3
|
+
require_relative './state_store'
|
3
4
|
require_relative './configuration'
|
4
5
|
require_relative './error'
|
5
6
|
|
@@ -8,13 +9,14 @@ module Rcb
|
|
8
9
|
attr_reader :config
|
9
10
|
|
10
11
|
# @param config [Rcb::Config]
|
11
|
-
def initialize(config)
|
12
|
+
def initialize(config, state_store:)
|
12
13
|
@config = config
|
14
|
+
@state_store = state_store || Rcb::StateStore::InMemory
|
13
15
|
end
|
14
16
|
|
15
17
|
def run!(&block)
|
16
18
|
result =
|
17
|
-
case
|
19
|
+
case get_state
|
18
20
|
in State::Close => s
|
19
21
|
s.run(config, &block)
|
20
22
|
in State::Open => s
|
@@ -25,40 +27,23 @@ module Rcb
|
|
25
27
|
|
26
28
|
case result
|
27
29
|
in Result::Ok[state, result]
|
28
|
-
|
30
|
+
@state_store.update(config.tag, state)
|
29
31
|
return result
|
30
32
|
in Result::Ng[state, error]
|
31
|
-
|
33
|
+
@state_store.update(config.tag, state)
|
32
34
|
raise error
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
36
38
|
def state
|
37
|
-
|
39
|
+
get_state.show_state(config)
|
38
40
|
end
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
class States
|
45
|
-
@states = {}
|
42
|
+
private
|
46
43
|
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
def self.of(tag)
|
52
|
-
@states[tag.to_sym] ||= State::Close.create
|
53
|
-
end
|
54
|
-
|
55
|
-
def self.update(tag, state)
|
56
|
-
@states[tag] = state
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.clear
|
60
|
-
@states = {}
|
61
|
-
end
|
44
|
+
def get_state
|
45
|
+
@state_store.get(config.tag) || State::Close.create
|
62
46
|
end
|
47
|
+
end
|
63
48
|
|
64
49
|
end
|
data/lib/rcb/state.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative './state'
|
2
|
+
require_relative './configuration'
|
3
|
+
|
4
|
+
module Rcb
|
5
|
+
module StateStore
|
6
|
+
class InMemory
|
7
|
+
@states = {}
|
8
|
+
|
9
|
+
def self.get(tag)
|
10
|
+
@states[tag.to_sym]
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.update(tag, state)
|
14
|
+
@states[tag] = state
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.clear
|
18
|
+
@states = {}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/rcb.rb
CHANGED
@@ -3,11 +3,11 @@ require_relative "./rcb/configuration"
|
|
3
3
|
|
4
4
|
module Rcb
|
5
5
|
module ClassMethods
|
6
|
-
def for(tag, open_condition: nil, reset_timeout_msec: nil)
|
6
|
+
def for(tag, state_store: nil, open_condition: nil, reset_timeout_msec: nil)
|
7
7
|
config = Rcb::Configurations.for(tag,
|
8
8
|
open_condition: open_condition,
|
9
9
|
reset_timeout_msec: reset_timeout_msec)
|
10
|
-
Instance.new(config)
|
10
|
+
Instance.new(config, state_store: state_store)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
data/rcb.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rcb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- petitviolet
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rstructural
|
@@ -88,6 +88,7 @@ files:
|
|
88
88
|
- lib/rcb/instance.rb
|
89
89
|
- lib/rcb/result.rb
|
90
90
|
- lib/rcb/state.rb
|
91
|
+
- lib/rcb/state_store.rb
|
91
92
|
- rcb.gemspec
|
92
93
|
homepage: https://github.com/petitviolet/rcb
|
93
94
|
licenses:
|