circuit_switch 0.2.1 → 0.4.1

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: 9281021c31b4e885f3e8c8ca7fbd1fd83e713202950776c910f9b0951891a5c6
4
- data.tar.gz: 8f4969657c64c2016724fabadd8d2cbddf063e6ffc3dd0298fb2e9e0b06e688a
3
+ metadata.gz: 4359ba3c58190ee7f16780a8475a9fe81051823faeaddf5b220d342ab9e9c294
4
+ data.tar.gz: ad985994dc31cb34e4090b9b45ebad4067e30b1b91d0419389867091d596ca37
5
5
  SHA512:
6
- metadata.gz: 94cc63d4de19ffdc4cea5a5e331af21ab458f26f5333a6ceb4b84c7b3ba13edb44ebee7c0379c555d1ea7f390e8a31cb159c35c8d181cd8dec4a16cb049507ab
7
- data.tar.gz: 2f490f1e01f4e05351cbde8ee6fe328e200c020dcbb0d83a1f627983a47c192f4c4ab8f5c3b3878bd58e7a026003d0bd79a5995044987b275b59b6d9902f478b
6
+ metadata.gz: 2517c69a923bb7739e6a5c0409b949b41ec624e5915c9fef7fae7e9e16be267983357f4e6c106702382c4157e81e9dae443159de70723bb66fe62247928096ad
7
+ data.tar.gz: 815d01eb8cc81480558f3eca996158f0174b59bab6a97985399ef0184b3890dd39d283df213ca014f2855939a2253e55918ad9790b51ed7ffcb14ce2891c290d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,48 @@
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
+
7
+ ## 0.4.0
8
+
9
+ ### Breaking Changes
10
+
11
+ * Be able to choice to notify `CircuitSwitch::CalledNotification` or `String`.
12
+ Improve `config/initializers/circuit_switch.rb` like following.
13
+
14
+ ```diff
15
+ CircuitSwitch.configure do |config|
16
+ - config.reporter = ->(message) { Bugsnag.notify(message) }
17
+ + config.reporter = ->(message, error) { Bugsnag.notify(error) }
18
+ ```
19
+
20
+ ## 0.3.0
21
+
22
+ ### Breaking Changes
23
+
24
+ * Modify `key` to unique by default.
25
+ To migrate, run next.
26
+
27
+ ```
28
+ rails generate circuit_switch:migration circuit_switch make_key_unique
29
+ rails db:migrate
30
+ ```
31
+
32
+ ### Changes
33
+
34
+ * Fix to save switch when block for `CircuitSwitch.run` raises error.
35
+
36
+ ## 0.2.2
37
+
38
+ ### New features
39
+
40
+ * Add `key_column_name` to configuration for aliasing `circuit_switches.key`.
41
+
42
+ ### Changes
43
+
44
+ * Declare dependent on ActiveSupport instead of implicitly dependent.
45
+
1
46
  ## 0.2.1
2
47
 
3
48
  ### New features
@@ -7,7 +52,7 @@
7
52
  To migrate, run next.
8
53
 
9
54
  ```
10
- rails generate circuit_switch:migration add_key
55
+ rails generate circuit_switch:migration circuit_switch add_key
11
56
  rails db:migrate
12
57
  ```
13
58
 
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,19 +111,17 @@ 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
- 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?`.
121
125
  Of course you can chain `report` and `run` or `open?`.
122
126
 
123
127
  #### `with_backtrace`
@@ -134,6 +138,24 @@ called_path: /app/services/greetings_service:21 block in validate
134
138
  /app/controllers/greetings_controller.rb:93 create
135
139
  ```
136
140
 
141
+ ## Test
142
+
143
+ To test, FactoryBot will look like this;
144
+
145
+ ```ruby
146
+ FactoryBot.define do
147
+ factory :circuit_switch, class: 'CircuitSwitch::CircuitSwitch' do
148
+ sequence(:key) { |n| "/path/to/file:#{n}" }
149
+ sequence(:caller) { |n| "/path/to/file:#{n}" }
150
+ due_date { Date.tomorrow }
151
+
152
+ trait :initially_closed do
153
+ run_is_terminated { true }
154
+ end
155
+ end
156
+ end
157
+ ```
158
+
137
159
  ## Task
138
160
 
139
161
  When find a problem and you want to terminate running or reporting right now, execute a task with it's caller.
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.add_dependency 'activejob'
27
27
  spec.add_dependency 'activerecord'
28
+ spec.add_dependency 'activesupport'
28
29
  spec.add_development_dependency 'byebug'
29
30
  spec.add_development_dependency 'sqlite3'
30
31
  spec.add_development_dependency 'test-unit'
@@ -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
@@ -25,6 +25,10 @@ module CircuitSwitch
25
25
  report_if.respond_to?(:call) ? report_if.call : !!report_if
26
26
  end
27
27
 
28
+ def key_column_name=(key)
29
+ ::CircuitSwitch::CircuitSwitch.alias_attribute :key, key
30
+ end
31
+
28
32
  def due_date
29
33
  @due_date ||= Date.today + 10
30
34
  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,24 +22,31 @@ 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
- RunCountUpdater.perform_later(
29
- key: key,
30
- limit_count: run_limit_count,
31
- called_path: called_path,
32
- reported: reported?,
33
- initially_closed: initially_closed
34
- )
35
30
  self
31
+ ensure
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
36
41
  end
37
42
 
38
43
  def execute_report
39
44
  if config.reporter.nil?
40
45
  raise CircuitSwitchError.new('Set config.reporter.')
41
46
  end
47
+ if config.reporter.arity == 1
48
+ Logger.new($stdout).info('config.reporter now receives 2 arguments. Improve your `config/initialzers/circuit_switch.rb`.')
49
+ end
42
50
  if stop_report_if_reach_limit && report_limit_count == 0
43
51
  raise CircuitSwitchError.new('Can\'t set limit_count to 0 when stop_report_if_reach_limit is true')
44
52
  end
@@ -51,6 +59,7 @@ module CircuitSwitch
51
59
  key: key,
52
60
  limit_count: report_limit_count,
53
61
  called_path: called_path,
62
+ stacktrace: StacktraceModifier.call(backtrace: caller),
54
63
  run: run?
55
64
  )
56
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
@@ -2,6 +2,8 @@ require 'active_record'
2
2
 
3
3
  module CircuitSwitch
4
4
  class CircuitSwitch < ::ActiveRecord::Base
5
+ validates :key, uniqueness: true
6
+
5
7
  after_initialize do |switch|
6
8
  switch.key ||= switch.caller
7
9
  end
@@ -28,11 +30,11 @@ module CircuitSwitch
28
30
  end
29
31
  end
30
32
 
31
- def increment_run_count
33
+ def increment_run_count!
32
34
  with_writable { update!(run_count: run_count + 1) }
33
35
  end
34
36
 
35
- def increment_report_count
37
+ def increment_report_count!
36
38
  with_writable { update!(report_count: report_count + 1) }
37
39
  end
38
40
 
@@ -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.2.1'
2
+ VERSION = '0.4.1'
3
3
  end
@@ -5,21 +5,35 @@ 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
 
12
- circuit_switch = key ? CircuitSwitch.find_by(key: key) : CircuitSwitch.find_by(caller: called_path)
13
- if run && circuit_switch.nil?
14
- raise ActiveRecord::RecordNotFound.new('Couldn\'t find CircuitSwitch::CircuitSwitch')
15
- end
12
+ first_raise = true
13
+ begin
14
+ circuit_switch = key ? CircuitSwitch.find_by(key: key) : CircuitSwitch.find_by(caller: called_path)
15
+ if run && circuit_switch.nil?
16
+ raise ActiveRecord::RecordNotFound.new('Couldn\'t find CircuitSwitch::CircuitSwitch')
17
+ end
18
+
19
+ circuit_switch ||= CircuitSwitch.new(key: key, caller: called_path)
20
+ circuit_switch.due_date ||= config.due_date
21
+ circuit_switch.assign(report_limit_count: limit_count).increment_report_count!
22
+ raise CalledNotification.new(circuit_switch.message)
23
+ rescue ActiveRecord::RecordInvalid => e
24
+ raise e unless first_raise
16
25
 
17
- circuit_switch ||= CircuitSwitch.new(key: key, caller: called_path)
18
- circuit_switch.due_date ||= config.due_date
19
- circuit_switch.assign(report_limit_count: limit_count).increment_report_count
20
- raise CalledNotification.new(circuit_switch.message)
21
- rescue CalledNotification => notification
22
- config.reporter.call(notification.to_message(called_path: called_path))
26
+ first_raise = false
27
+ sleep(2)
28
+ retry
29
+ rescue CalledNotification => notification
30
+ notification.set_backtrace(stacktrace)
31
+ if config.reporter.arity == 1
32
+ config.reporter.call(notification.to_message(called_path: called_path))
33
+ else
34
+ config.reporter.call(notification.to_message(called_path: called_path), notification)
35
+ end
36
+ end
23
37
  end
24
38
  end
25
39
  end
@@ -9,14 +9,23 @@ module CircuitSwitch
9
9
  # Wait for Reporter saves circuit_switch
10
10
  sleep(3) if reported
11
11
 
12
- circuit_switch = key ? CircuitSwitch.find_by(key: key) : CircuitSwitch.find_by(caller: called_path)
13
- if reported && circuit_switch.nil?
14
- raise ActiveRecord::RecordNotFound.new('Couldn\'t find CircuitSwitch::CircuitSwitch')
15
- end
12
+ first_raise = true
13
+ begin
14
+ circuit_switch = key ? CircuitSwitch.find_by(key: key) : CircuitSwitch.find_by(caller: called_path)
15
+ if reported && circuit_switch.nil?
16
+ raise ActiveRecord::RecordNotFound.new('Couldn\'t find CircuitSwitch::CircuitSwitch')
17
+ end
18
+
19
+ circuit_switch ||= CircuitSwitch.new(key: key, caller: called_path, run_is_terminated: initially_closed)
20
+ circuit_switch.due_date ||= config.due_date
21
+ circuit_switch.assign(run_limit_count: limit_count).increment_run_count!
22
+ rescue ActiveRecord::RecordInvalid => e
23
+ raise e unless first_raise
16
24
 
17
- circuit_switch ||= CircuitSwitch.new(key: key, caller: called_path, run_is_terminated: initially_closed)
18
- circuit_switch.due_date ||= config.due_date
19
- circuit_switch.assign(run_limit_count: limit_count).increment_run_count
25
+ first_raise = false
26
+ sleep(2)
27
+ retry
28
+ end
20
29
  end
21
30
  end
22
31
  end
@@ -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
@@ -5,12 +5,15 @@ module CircuitSwitch
5
5
  desc 'Create a migration to manage circuit switches state'
6
6
  source_root File.expand_path('templates', __dir__)
7
7
  argument :migration_type, required: false, type: :array, default: ['create'],
8
- desc: 'Type of migration to create or add key column. By default to create.',
8
+ desc: 'Type of migration to create or add key column or make key unique. By default to create.',
9
9
  banner: 'create or add_key'
10
10
 
11
11
  def generate_migration
12
- if migration_type == ['add_key']
12
+ case migration_type
13
+ when ['add_key']
13
14
  migration_template 'add_key.rb.erb', 'db/migrate/add_key_to_circuit_switches.rb', migration_version: migration_version
15
+ when ['make_key_unique']
16
+ migration_template 'make_key_unique.rb.erb', 'db/migrate/make_key_unique_for_circuit_switches.rb', migration_version: migration_version
14
17
  else
15
18
  migration_template 'migration.rb.erb', 'db/migrate/create_circuit_switches.rb', migration_version: migration_version
16
19
  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
@@ -16,6 +17,9 @@ CircuitSwitch.configure do |config|
16
17
  # Excluded paths to report
17
18
  # config.silent_paths = [CIRCUIT_SWITCH]
18
19
 
20
+ # Alias column name for circuit_switches.key through alias_attribute
21
+ # config.key_column_name = :key
22
+
19
23
  # Notifier to notify circuit_switch's due_date come and it's time to clean code!
20
24
  # Specify proc to call your report tool: like;
21
25
  # config.due_date_notifier = -> (message) { Slack::Web::Client.new.chat_postMessage(channel: '#your_channel', text: message) }
@@ -26,11 +30,10 @@ CircuitSwitch.configure do |config|
26
30
 
27
31
  # Option to contain error backtrace for report
28
32
  # You don't need backtrace when you report to some bug report tool.
29
- # You may be want backtrace when report to plain feed; e.g. Slack or email.
33
+ # You may want backtrace when reporting to a plain feed; e.g. Slack or email.
30
34
  # config.with_backtrace = false
31
35
 
32
36
  # Allowed backtrace paths to report
33
- # Specify with `with_backtrace` option.
34
37
  # Allowed all paths when set `[]`.
35
38
  # config.allowed_backtrace_paths = [Dir.pwd]
36
39
 
@@ -0,0 +1,11 @@
1
+ class MakeKeyUniqueForCircuitSwitches < ActiveRecord::Migration<%= migration_version %>
2
+ def up
3
+ remove_index :circuit_switches, :key
4
+ add_index :circuit_switches, :key, unique: true
5
+ end
6
+
7
+ def down
8
+ remove_index :circuit_switches, :key
9
+ add_index :circuit_switches, :key
10
+ end
11
+ end
@@ -1,7 +1,7 @@
1
1
  class CreateCircuitSwitches < ActiveRecord::Migration<%= migration_version %>
2
2
  def change
3
3
  create_table :circuit_switches do |t|
4
- t.string :key, null: false, index: true
4
+ t.string :key, null: false
5
5
  t.string :caller, null: false
6
6
  t.integer :run_count, default: 0, null: false
7
7
  t.integer :run_limit_count, default: 10, null: false
@@ -12,5 +12,7 @@ class CreateCircuitSwitches < ActiveRecord::Migration<%= migration_version %>
12
12
  t.date :due_date, null: false
13
13
  t.timestamps
14
14
  end
15
+
16
+ add_index :circuit_switches, [:key], unique: true
15
17
  end
16
18
  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.2.1
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-10-19 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
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: byebug
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -131,6 +145,7 @@ files:
131
145
  - lib/generators/circuit_switch/migration_generator.rb
132
146
  - lib/generators/circuit_switch/templates/add_key.rb.erb
133
147
  - lib/generators/circuit_switch/templates/initializer.rb
148
+ - lib/generators/circuit_switch/templates/make_key_unique.rb.erb
134
149
  - lib/generators/circuit_switch/templates/migration.rb.erb
135
150
  homepage: https://github.com/makicamel/circuit_switch
136
151
  licenses: