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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a00a04ad121a8f40a84f78a55e769aaa8f3fc185ac58fab51ddff11a0678e28
4
- data.tar.gz: '06189169b6959b97e8a33617f2d9e054f9acf3d55bce2833b39a5f6567a061c6'
3
+ metadata.gz: f1e87399b178858a0b41fce787342117deab9d4a1a29c7d9262d742be2633641
4
+ data.tar.gz: fdf0d9ec8723b02fea239de819f60e98b24de9904d034a40f549bcf90d895f26
5
5
  SHA512:
6
- metadata.gz: b63203a04cb3a37e4c6ac265eb8283fdde5b5cb5990c4234bb57876d72c5c26e48ade13907373046dc9f4b8f943f8c6a34e8c6957bceae9ba3857ca087c9c033
7
- data.tar.gz: ff59240799e6841334eaffcaa76706cd78268804f8dc263da2c57dfd2bdc480264768ba614fb4102186fa483750ff36eb7c2c0bcc87eb6836f70c0025bcd0361
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, 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 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.
62
- `run` receives optional arguments.
63
-
64
- - `key`: [String] Named key to find switch instead of caller
65
- If no key passed, use caller.
66
- - `if`: [Boolean, Proc] Call proc when `if` is truthy (default: true)
67
- - `close_if`: [Boolean, Proc] Call proc when `close_if` is falsy (default: false)
68
- - `close_if_reach_limit`: [Boolean] Stop calling proc when run count reaches limit (default: false)
69
- - `limit_count`: [Integer] Limit count. Use `run_limit_count` default value if it's nil (default: nil)
70
- Can't be set 0 when `close_if_reach_limit` is true
71
- - `initially_closed`: [Boolean] Create switch with terminated mode (default: false)
72
-
73
- To close the circuit at specific date or when called 1000 times, code goes like:
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(close_if: -> { Date.today >= some_day }, limit_count: 1_000) do
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 the line of code is called. It doesn't receive proc. It's useful for refactoring or removing dead codes.
109
- Same as `run`, some conditions can be set. By default, reporting is stopped when reached the specified count. The default count is 10. To change this default value, modify `circuit_switches.report_limit_count` default value in the migration file.
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] Named key to find switch instead of caller
113
- If no key passed, use caller.
114
- - `if`: [Boolean, Proc] Report when `if` is truthy (default: true)
115
- - `stop_report_if`: [Boolean, Proc] Report when `close_if` is falsy (default: false)
116
- - `stop_report_if_reach_limit`: [Boolean] Stop reporting when reported count reaches limit (default: true)
117
- - `limit_count`: [Integer] Limit count. Use `report_limit_count` default value if it's nil (default: nil)
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?`.
@@ -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
@@ -1,3 +1,3 @@
1
1
  module CircuitSwitch
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -27,7 +27,11 @@ module CircuitSwitch
27
27
  sleep(2)
28
28
  retry
29
29
  rescue CalledNotification => notification
30
- config.reporter.call(notification.to_message(called_path: called_path))
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(message) }
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.3.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-03 00:00:00.000000000 Z
11
+ date: 2021-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob