circuit_switch 0.4.0 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1e87399b178858a0b41fce787342117deab9d4a1a29c7d9262d742be2633641
4
- data.tar.gz: fdf0d9ec8723b02fea239de819f60e98b24de9904d034a40f549bcf90d895f26
3
+ metadata.gz: 4359ba3c58190ee7f16780a8475a9fe81051823faeaddf5b220d342ab9e9c294
4
+ data.tar.gz: ad985994dc31cb34e4090b9b45ebad4067e30b1b91d0419389867091d596ca37
5
5
  SHA512:
6
- metadata.gz: 075c7f6dfeef30c3e0faecadf30969dfa6cd1f8fd2b5e4e6f5934f0e15913ec98f4f6b8a3cf9c414a17e7b920d17ee22a01abcea18c9cf8af4bfc510562c8aba
7
- data.tar.gz: 6df8910491782a75b873952c26e0ac5ebdb27aadcf93727fc044e1b5dd0eeb6bfcfceac04c30417b8f86b6ac1d0e6515b342dd8d0616fc0dc9f78f680816a232
6
+ metadata.gz: 2517c69a923bb7739e6a5c0409b949b41ec624e5915c9fef7fae7e9e16be267983357f4e6c106702382c4157e81e9dae443159de70723bb66fe62247928096ad
7
+ data.tar.gz: 815d01eb8cc81480558f3eca996158f0174b59bab6a97985399ef0184b3890dd39d283df213ca014f2855939a2253e55918ad9790b51ed7ffcb14ce2891c290d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.4.1
2
+
3
+ * Fix bug `if` `stop_report_if_reach_limit` options don't receive `false`.
4
+ * Fix to report error with stacktrace.
5
+ * Fix not to update run count when run isn't executable.
6
+
1
7
  ## 0.4.0
2
8
 
3
9
  ### Breaking Changes
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 about report is executed or not, you can get through `report?`.
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
- }.select { |_, v| v }
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
- }.select { |_, v| v }
61
+ }.reject { |_, v| v.nil? }
62
62
  assign_reporter(**arguments)
63
63
  execute_report
64
64
  end
@@ -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
- RunCountUpdater.perform_later(
31
- key: key,
32
- limit_count: run_limit_count,
33
- called_path: called_path,
34
- reported: reported?,
35
- initially_closed: initially_closed
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#{StacktraceModifier.call(backtrace: backtrace)}"
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
- backtrace
10
- .select { |path| /(#{config.allowed_backtrace_paths.join('|')})/.match?(path) }
11
- .map { |path| path.sub(/(#{config.strip_paths.join('|')})/, '') }
12
- .join("\n")
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
@@ -1,3 +1,3 @@
1
1
  module CircuitSwitch
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.1'
3
3
  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
@@ -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
- }.select { |_, v| v }
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
- }.select { |_, v| v }
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
- }.select { |_, v| v }
79
+ }.reject { |_, v| v.nil? }
80
80
  Builder.new.run(**arguments) {}.run?
81
81
  end
82
82
  end
@@ -34,7 +34,6 @@ CircuitSwitch.configure do |config|
34
34
  # config.with_backtrace = false
35
35
 
36
36
  # Allowed backtrace paths to report
37
- # Specify with `with_backtrace` option.
38
37
  # Allowed all paths when set `[]`.
39
38
  # config.allowed_backtrace_paths = [Dir.pwd]
40
39
 
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.0
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-09 00:00:00.000000000 Z
11
+ date: 2021-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob