circuit_switch 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +27 -0
- data/CHANGELOG.md +6 -0
- data/README.md +4 -3
- data/Rakefile +9 -1
- data/lib/circuit_switch/core.rb +7 -3
- data/lib/circuit_switch/stacktrace_modifier.rb +1 -1
- data/lib/circuit_switch/version.rb +1 -1
- data/lib/circuit_switch.rb +2 -2
- 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: d036ceb2748b3432749f5a03d83d324b59d1acb340bb7d64cbe3ef86f5531c4f
|
4
|
+
data.tar.gz: 32b8e3dbe02c1eaf8e25b40ab26f97036ecf33402bf974e6b71cb989db8c3178
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa10c7a2196b37619dc94605efca82c8b3ce5b3182063004911f8aa28bef44f711e945adc73f38857e85a40a6f005b1139a7fac990e76e39a45080e481a93c3f
|
7
|
+
data.tar.gz: 3619df1cd293ba93f271ca536bcb55f4152a20810e52fb7aba16cd44e11b6bd081645bc1804f4f01c47a49c056a1793e840de5715f4c54126b4bdda8887f1d0c
|
@@ -0,0 +1,27 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on: [push,pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
strategy:
|
8
|
+
fail-fast: false
|
9
|
+
matrix:
|
10
|
+
os: [ubuntu-latest, windows-latest, macos-latest]
|
11
|
+
ruby: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0, head, truffleruby]
|
12
|
+
exclude:
|
13
|
+
- os: windows-latest
|
14
|
+
ruby: head
|
15
|
+
- os: windows-latest
|
16
|
+
ruby: truffleruby
|
17
|
+
runs-on: ${{ matrix.os }}
|
18
|
+
steps:
|
19
|
+
- uses: actions/checkout@v2
|
20
|
+
- name: Set up Ruby
|
21
|
+
uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: ${{ matrix.ruby }}
|
24
|
+
bundler-cache: true
|
25
|
+
- name: Run the default task
|
26
|
+
run: |
|
27
|
+
bundle exec rake
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -57,12 +57,13 @@ end
|
|
57
57
|
```
|
58
58
|
|
59
59
|
`run` calls received proc, and when conditions are met, closes it's circuit.
|
60
|
-
To switch circuit opening and closing, some conditions can be set. By default, the circuit is
|
60
|
+
To switch circuit opening and closing, some conditions can be set. By default, the circuit is always opened.
|
61
|
+
You can also set `limit_count` to close circuit when reached the specified count. Default limit_count is 10. To change this default value, modify `circuit_switches.run_limit_count` default value in the migration file.
|
61
62
|
`run` receives optional arguments.
|
62
63
|
|
63
64
|
- `if`: [Boolean, Proc] Call proc when `if` is truthy (default: true)
|
64
65
|
- `close_if`: [Boolean, Proc] Call proc when `close_if` is falsy (default: false)
|
65
|
-
- `close_if_reach_limit`: [Boolean] Stop calling proc when run count reaches limit (default:
|
66
|
+
- `close_if_reach_limit`: [Boolean] Stop calling proc when run count reaches limit (default: false)
|
66
67
|
- `limit_count`: [Integer] Limit count. Use `run_limit_count` default value if it's nil (default: nil)
|
67
68
|
Can't be set 0 when `close_if_reach_limit` is true
|
68
69
|
|
@@ -83,7 +84,7 @@ unless circuit_open
|
|
83
84
|
end
|
84
85
|
```
|
85
86
|
|
86
|
-
`CircuitSwitch.run.run?` has syntax sugar. `open
|
87
|
+
`CircuitSwitch.run.run?` has syntax sugar. `open?` doesn't receive proc.
|
87
88
|
|
88
89
|
```ruby
|
89
90
|
if CircuitSwitch.open?
|
data/Rakefile
CHANGED
data/lib/circuit_switch/core.rb
CHANGED
@@ -5,13 +5,17 @@ module CircuitSwitch
|
|
5
5
|
def run(
|
6
6
|
if: true,
|
7
7
|
close_if: false,
|
8
|
-
close_if_reach_limit:
|
8
|
+
close_if_reach_limit: nil,
|
9
9
|
limit_count: nil,
|
10
10
|
&block
|
11
11
|
)
|
12
12
|
if close_if_reach_limit && limit_count == 0
|
13
13
|
raise CircuitSwitchError.new('Can\'t set limit_count to 0 when close_if_reach_limit is true')
|
14
14
|
end
|
15
|
+
if close_if_reach_limit.nil?
|
16
|
+
Logger.new($stdout).warn('Default value for close_if_reach_limit is modified from true to false at ver 0.2.0.')
|
17
|
+
close_if_reach_limit = false
|
18
|
+
end
|
15
19
|
return self if evaluate(close_if) || !evaluate(binding.local_variable_get(:if))
|
16
20
|
return self if close_if_reach_limit && switch.reached_run_limit?(limit_count)
|
17
21
|
return self if switch.run_is_terminated?
|
@@ -70,8 +74,8 @@ module CircuitSwitch
|
|
70
74
|
|
71
75
|
def called_path
|
72
76
|
@called_path ||= caller
|
73
|
-
.reject { |path|
|
74
|
-
.detect { |path|
|
77
|
+
.reject { |path| /(#{config.silent_paths.join('|')})/.match?(path) }
|
78
|
+
.detect { |path| /(#{config.report_paths.join('|')})/.match?(path) }
|
75
79
|
&.sub(/(#{config.strip_paths.join('|')})/, '')
|
76
80
|
&.gsub(/[`']/, '') ||
|
77
81
|
"/somewhere/in/library:in #{Date.today}"
|
@@ -7,7 +7,7 @@ module CircuitSwitch
|
|
7
7
|
|
8
8
|
def call(backtrace:)
|
9
9
|
backtrace
|
10
|
-
.select { |path|
|
10
|
+
.select { |path| /(#{config.allowed_backtrace_paths.join('|')})/.match?(path) }
|
11
11
|
.map { |path| path.sub(/(#{config.strip_paths.join('|')})/, '') }
|
12
12
|
.join("\n")
|
13
13
|
end
|
data/lib/circuit_switch.rb
CHANGED
@@ -20,14 +20,14 @@ module CircuitSwitch
|
|
20
20
|
|
21
21
|
# @param if [Boolean, Proc] Call proc when `if` is truthy (default: true)
|
22
22
|
# @param close_if [Boolean, Proc] Call proc when `close_if` is falsy (default: false)
|
23
|
-
# @param close_if_reach_limit [Boolean] Stop calling proc when run count reaches limit (default:
|
23
|
+
# @param close_if_reach_limit [Boolean] Stop calling proc when run count reaches limit (default: false)
|
24
24
|
# @param limit_count [Integer] Limit count. Use `run_limit_count` default value if it's nil
|
25
25
|
# Can't be set 0 when `close_if_reach_limit` is true (default: nil)
|
26
26
|
# @param [Proc] block
|
27
27
|
def run(
|
28
28
|
if: true,
|
29
29
|
close_if: false,
|
30
|
-
close_if_reach_limit:
|
30
|
+
close_if_reach_limit: nil,
|
31
31
|
limit_count: nil,
|
32
32
|
&block
|
33
33
|
)
|
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.2.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-10-
|
11
|
+
date: 2021-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -102,6 +102,7 @@ executables: []
|
|
102
102
|
extensions: []
|
103
103
|
extra_rdoc_files: []
|
104
104
|
files:
|
105
|
+
- ".github/workflows/main.yml"
|
105
106
|
- ".gitignore"
|
106
107
|
- CHANGELOG.md
|
107
108
|
- CODE_OF_CONDUCT.md
|