circuit_switch 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +1 -1
- data/lib/circuit_switch/builder.rb +2 -2
- data/lib/circuit_switch/core.rb +12 -7
- data/lib/circuit_switch/notification.rb +1 -1
- data/lib/circuit_switch/stacktrace_modifier.rb +8 -4
- data/lib/circuit_switch/version.rb +1 -1
- data/lib/circuit_switch/workers/reporter.rb +2 -1
- data/lib/circuit_switch.rb +3 -3
- data/lib/generators/circuit_switch/templates/initializer.rb +0 -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: 4359ba3c58190ee7f16780a8475a9fe81051823faeaddf5b220d342ab9e9c294
|
4
|
+
data.tar.gz: ad985994dc31cb34e4090b9b45ebad4067e30b1b91d0419389867091d596ca37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2517c69a923bb7739e6a5c0409b949b41ec624e5915c9fef7fae7e9e16be267983357f4e6c106702382c4157e81e9dae443159de70723bb66fe62247928096ad
|
7
|
+
data.tar.gz: 815d01eb8cc81480558f3eca996158f0174b59bab6a97985399ef0184b3890dd39d283df213ca014f2855939a2253e55918ad9790b51ed7ffcb14ce2891c290d
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -121,7 +121,7 @@ Same as `run`, a set of options can be set. By default, this method does not sen
|
|
121
121
|
- `limit_count`: [Integer] Mutates `circuit_switches.report_limit_count` whose value defined in schema is 10 by default. (default: nil)
|
122
122
|
Can't be set to 0 when `stop_report_if_reach_limit` is true.
|
123
123
|
|
124
|
-
To know
|
124
|
+
To know if `report` has already been executed or not, you can get through `reported?`.
|
125
125
|
Of course you can chain `report` and `run` or `open?`.
|
126
126
|
|
127
127
|
#### `with_backtrace`
|
@@ -46,7 +46,7 @@ module CircuitSwitch
|
|
46
46
|
close_if_reach_limit: close_if_reach_limit,
|
47
47
|
limit_count: limit_count,
|
48
48
|
initially_closed: initially_closed,
|
49
|
-
}.
|
49
|
+
}.reject { |_, v| v.nil? }
|
50
50
|
assign_runner(**arguments)
|
51
51
|
execute_run(&block)
|
52
52
|
end
|
@@ -58,7 +58,7 @@ module CircuitSwitch
|
|
58
58
|
stop_report_if: stop_report_if,
|
59
59
|
stop_report_if_reach_limit: stop_report_if_reach_limit,
|
60
60
|
limit_count: limit_count
|
61
|
-
}.
|
61
|
+
}.reject { |_, v| v.nil? }
|
62
62
|
assign_reporter(**arguments)
|
63
63
|
execute_report
|
64
64
|
end
|
data/lib/circuit_switch/core.rb
CHANGED
@@ -9,6 +9,7 @@ module CircuitSwitch
|
|
9
9
|
:report_if, :stop_report_if, :stop_report_if_reach_limit, :report_limit_count
|
10
10
|
|
11
11
|
def execute_run(&block)
|
12
|
+
run_executable = false
|
12
13
|
if close_if_reach_limit && run_limit_count == 0
|
13
14
|
raise CircuitSwitchError.new('Can\'t set limit_count to 0 when close_if_reach_limit is true')
|
14
15
|
end
|
@@ -21,19 +22,22 @@ module CircuitSwitch
|
|
21
22
|
return self if close_if_reach_limit && switch.reached_run_limit?(run_limit_count)
|
22
23
|
return self if switch.run_is_terminated?
|
23
24
|
|
25
|
+
run_executable = true
|
24
26
|
unless switch.new_record? && initially_closed
|
25
27
|
yield
|
26
28
|
@run = true
|
27
29
|
end
|
28
30
|
self
|
29
31
|
ensure
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
if run_executable
|
33
|
+
RunCountUpdater.perform_later(
|
34
|
+
key: key,
|
35
|
+
limit_count: run_limit_count,
|
36
|
+
called_path: called_path,
|
37
|
+
reported: reported?,
|
38
|
+
initially_closed: initially_closed
|
39
|
+
)
|
40
|
+
end
|
37
41
|
end
|
38
42
|
|
39
43
|
def execute_report
|
@@ -55,6 +59,7 @@ module CircuitSwitch
|
|
55
59
|
key: key,
|
56
60
|
limit_count: report_limit_count,
|
57
61
|
called_path: called_path,
|
62
|
+
stacktrace: StacktraceModifier.call(backtrace: caller),
|
58
63
|
run: run?
|
59
64
|
)
|
60
65
|
@reported = true
|
@@ -10,7 +10,7 @@ module CircuitSwitch
|
|
10
10
|
class CalledNotification < CircuitSwitchNotification
|
11
11
|
def to_message(called_path:)
|
12
12
|
if ::CircuitSwitch.config.with_backtrace
|
13
|
-
"#{message}\ncalled_path: #{called_path}\n#{
|
13
|
+
"#{message}\ncalled_path: #{called_path}\n#{backtrace.join("\n")}"
|
14
14
|
else
|
15
15
|
message
|
16
16
|
end
|
@@ -6,10 +6,14 @@ module CircuitSwitch
|
|
6
6
|
delegate :config, to: ::CircuitSwitch
|
7
7
|
|
8
8
|
def call(backtrace:)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
if config.with_backtrace
|
10
|
+
backtrace
|
11
|
+
.select { |path| /(#{config.allowed_backtrace_paths.join('|')})/.match?(path) }
|
12
|
+
.map { |path| path.sub(/(#{config.strip_paths.join('|')})/, '') }
|
13
|
+
else
|
14
|
+
backtrace
|
15
|
+
.select { |path| /(#{config.allowed_backtrace_paths.join('|')})/.match?(path) }
|
16
|
+
end
|
13
17
|
end
|
14
18
|
end
|
15
19
|
end
|
@@ -5,7 +5,7 @@ module CircuitSwitch
|
|
5
5
|
class Reporter < ::ActiveJob::Base
|
6
6
|
delegate :config, to: ::CircuitSwitch
|
7
7
|
|
8
|
-
def perform(key:, limit_count:, called_path:, run:)
|
8
|
+
def perform(key:, limit_count:, called_path:, stacktrace:, run:)
|
9
9
|
# Wait for RunCountUpdater saves circuit_switch
|
10
10
|
sleep(3) if run
|
11
11
|
|
@@ -27,6 +27,7 @@ module CircuitSwitch
|
|
27
27
|
sleep(2)
|
28
28
|
retry
|
29
29
|
rescue CalledNotification => notification
|
30
|
+
notification.set_backtrace(stacktrace)
|
30
31
|
if config.reporter.arity == 1
|
31
32
|
config.reporter.call(notification.to_message(called_path: called_path))
|
32
33
|
else
|
data/lib/circuit_switch.rb
CHANGED
@@ -31,7 +31,7 @@ module CircuitSwitch
|
|
31
31
|
close_if_reach_limit: close_if_reach_limit,
|
32
32
|
limit_count: limit_count,
|
33
33
|
initially_closed: initially_closed,
|
34
|
-
}.
|
34
|
+
}.reject { |_, v| v.nil? }
|
35
35
|
Builder.new.run(**arguments, &block)
|
36
36
|
end
|
37
37
|
|
@@ -52,7 +52,7 @@ module CircuitSwitch
|
|
52
52
|
stop_report_if: stop_report_if,
|
53
53
|
stop_report_if_reach_limit: stop_report_if_reach_limit,
|
54
54
|
limit_count: limit_count
|
55
|
-
}.
|
55
|
+
}.reject { |_, v| v.nil? }
|
56
56
|
Builder.new.report(**arguments)
|
57
57
|
end
|
58
58
|
|
@@ -76,7 +76,7 @@ module CircuitSwitch
|
|
76
76
|
close_if_reach_limit: close_if_reach_limit,
|
77
77
|
limit_count: limit_count,
|
78
78
|
initially_closed: initially_closed,
|
79
|
-
}.
|
79
|
+
}.reject { |_, v| v.nil? }
|
80
80
|
Builder.new.run(**arguments) {}.run?
|
81
81
|
end
|
82
82
|
end
|
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.
|
4
|
+
version: 0.4.1
|
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-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|