circuit_switch 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +30 -26
- data/lib/circuit_switch/core.rb +3 -0
- data/lib/circuit_switch/version.rb +1 -1
- data/lib/circuit_switch/workers/reporter.rb +5 -1
- data/lib/generators/circuit_switch/templates/initializer.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1e87399b178858a0b41fce787342117deab9d4a1a29c7d9262d742be2633641
|
4
|
+
data.tar.gz: fdf0d9ec8723b02fea239de819f60e98b24de9904d034a40f549bcf90d895f26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 075c7f6dfeef30c3e0faecadf30969dfa6cd1f8fd2b5e4e6f5934f0e15913ec98f4f6b8a3cf9c414a17e7b920d17ee22a01abcea18c9cf8af4bfc510562c8aba
|
7
|
+
data.tar.gz: 6df8910491782a75b873952c26e0ac5ebdb27aadcf93727fc044e1b5dd0eeb6bfcfceac04c30417b8f86b6ac1d0e6515b342dd8d0616fc0dc9f78f680816a232
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
## 0.4.0
|
2
|
+
|
3
|
+
### Breaking Changes
|
4
|
+
|
5
|
+
* Be able to choice to notify `CircuitSwitch::CalledNotification` or `String`.
|
6
|
+
Improve `config/initializers/circuit_switch.rb` like following.
|
7
|
+
|
8
|
+
```diff
|
9
|
+
CircuitSwitch.configure do |config|
|
10
|
+
- config.reporter = ->(message) { Bugsnag.notify(message) }
|
11
|
+
+ config.reporter = ->(message, error) { Bugsnag.notify(error) }
|
12
|
+
```
|
13
|
+
|
1
14
|
## 0.3.0
|
2
15
|
|
3
16
|
### Breaking Changes
|
data/README.md
CHANGED
@@ -56,24 +56,30 @@ CircuitSwitch.run do
|
|
56
56
|
end
|
57
57
|
```
|
58
58
|
|
59
|
-
`run` calls received proc
|
60
|
-
To switch circuit opening and closing,
|
61
|
-
You can
|
62
|
-
|
63
|
-
|
64
|
-
- `
|
65
|
-
|
66
|
-
- `
|
67
|
-
- `
|
68
|
-
|
69
|
-
- `
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
59
|
+
`run` basically calls the received proc. But when a condition is met, it closes the circuit and does not evaluate the proc.
|
60
|
+
To switch circuit opening and closing, a set of options can be set. Without options, the circuit is always open.
|
61
|
+
You can set `close_if_reach_limit: true` so that the circuit is only open for 10 invocations. The constant 10 comes from the table definition we have arbitrarily chosen. In case you need a larger number, specify it in the `limit_count` option in combination with `close_if_reach_limit: true`, or alter default constraint on `circuit_switches.run_limit_count`.
|
62
|
+
|
63
|
+
- `key`: [String] The identifier to find record by. If `key` has not been passed, `circuit_switches.caller` is chosen as an alternative.
|
64
|
+
- `if`: [Boolean, Proc] Calls proc when the value of `if` is evaluated truthy (default: true)
|
65
|
+
- `close_if`: [Boolean, Proc] Calls proc when the value of `close_if` is evaluated falsy (default: false)
|
66
|
+
- `close_if_reach_limit`: [Boolean] Stops calling proc when `circuit_switches.run_count` has reached `circuit_switches.run_limit_count` (default: false)
|
67
|
+
- `limit_count`: [Integer] Mutates `circuit_switches.run_limit_count` whose value defined in schema is 10 by default. (default: nil)
|
68
|
+
Can't be set to 0 when `close_if_reach_limit` is true. This option is only relevant when `close_if_reach_limit` is set to true.
|
69
|
+
- `initially_closed`: [Boolean] Creates switch with terminated mode (default: false)
|
70
|
+
|
71
|
+
To close the circuit at a specific date, code goes like:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
CircuitSwitch.run(close_if: -> { Date.today >= some_day }) do
|
75
|
+
# testing codes
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
Or when the code of concern has been called 1000 times:
|
74
80
|
|
75
81
|
```ruby
|
76
|
-
CircuitSwitch.run(
|
82
|
+
CircuitSwitch.run(close_if_reach_limit: true, limit_count: 1_000) do
|
77
83
|
# testing codes
|
78
84
|
end
|
79
85
|
```
|
@@ -105,17 +111,15 @@ When you just want to report, set your `reporter` to initializer and then call `
|
|
105
111
|
CircuitSwitch.report(if: some_condition)
|
106
112
|
```
|
107
113
|
|
108
|
-
`report` just reports
|
109
|
-
Same as `run`,
|
110
|
-
`report` receives optional arguments.
|
114
|
+
`report` just reports which line of code is called. It doesn't receive proc. It's useful for refactoring or removing dead codes.
|
115
|
+
Same as `run`, a set of options can be set. By default, this method does not send reports more than 10 times. The constant 10 comes from the table definition we have arbitrarily chosen. In case you need a larger number, specify it in the `limit_count` option, or alter default constraint on `circuit_switches.report_limit_count`.
|
111
116
|
|
112
|
-
- `key`: [String]
|
113
|
-
|
114
|
-
- `
|
115
|
-
- `
|
116
|
-
- `
|
117
|
-
|
118
|
-
Can't be set 0 when `stop_report_if_reach_limit` is true
|
117
|
+
- `key`: [String] The identifier to find record by. If `key` has not been passed, `circuit_switches.caller` is chosen as an alternative.
|
118
|
+
- `if`: [Boolean, Proc] Reports when the value of `if` is evaluated truthy (default: true)
|
119
|
+
- `stop_report_if`: [Boolean, Proc] Reports when the value of `stop_report_if` is evaluated falsy (default: false)
|
120
|
+
- `stop_report_if_reach_limit`: [Boolean] Stops reporting when `circuit_switches.report_count` has reached `circuit_switches.report_limit_count` (default: true)
|
121
|
+
- `limit_count`: [Integer] Mutates `circuit_switches.report_limit_count` whose value defined in schema is 10 by default. (default: nil)
|
122
|
+
Can't be set to 0 when `stop_report_if_reach_limit` is true.
|
119
123
|
|
120
124
|
To know about report is executed or not, you can get through `report?`.
|
121
125
|
Of course you can chain `report` and `run` or `open?`.
|
data/lib/circuit_switch/core.rb
CHANGED
@@ -40,6 +40,9 @@ module CircuitSwitch
|
|
40
40
|
if config.reporter.nil?
|
41
41
|
raise CircuitSwitchError.new('Set config.reporter.')
|
42
42
|
end
|
43
|
+
if config.reporter.arity == 1
|
44
|
+
Logger.new($stdout).info('config.reporter now receives 2 arguments. Improve your `config/initialzers/circuit_switch.rb`.')
|
45
|
+
end
|
43
46
|
if stop_report_if_reach_limit && report_limit_count == 0
|
44
47
|
raise CircuitSwitchError.new('Can\'t set limit_count to 0 when stop_report_if_reach_limit is true')
|
45
48
|
end
|
@@ -27,7 +27,11 @@ module CircuitSwitch
|
|
27
27
|
sleep(2)
|
28
28
|
retry
|
29
29
|
rescue CalledNotification => notification
|
30
|
-
config.reporter.
|
30
|
+
if config.reporter.arity == 1
|
31
|
+
config.reporter.call(notification.to_message(called_path: called_path))
|
32
|
+
else
|
33
|
+
config.reporter.call(notification.to_message(called_path: called_path), notification)
|
34
|
+
end
|
31
35
|
end
|
32
36
|
end
|
33
37
|
end
|
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
CircuitSwitch.configure do |config|
|
4
4
|
# Specify proc to call your report tool: like;
|
5
|
-
# config.reporter = -> (message) { Bugsnag.notify(
|
5
|
+
# config.reporter = -> (message, error) { Bugsnag.notify(error) }
|
6
|
+
# config.reporter = -> (message, error) { Sentry::Rails.capture_message(message) }
|
6
7
|
config.reporter = nil
|
7
8
|
|
8
9
|
# Condition to report
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: circuit_switch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- makicamel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|