Class: CircuitSwitch::CircuitSwitch

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/circuit_switch/orm/active_record/circuit_switch.rb

Instance Method Summary collapse

Instance Method Details

#assign(run_limit_count: nil, report_limit_count: nil) ⇒ Object



11
12
13
14
15
# File 'lib/circuit_switch/orm/active_record/circuit_switch.rb', line 11

def assign(run_limit_count: nil, report_limit_count: nil)
  self.run_limit_count = run_limit_count if run_limit_count
  self.report_limit_count = report_limit_count if report_limit_count
  self
end

#increment_report_count!Object



37
38
39
# File 'lib/circuit_switch/orm/active_record/circuit_switch.rb', line 37

def increment_report_count!
  with_writable { update!(report_count: report_count + 1) }
end

#increment_run_count!Object



33
34
35
# File 'lib/circuit_switch/orm/active_record/circuit_switch.rb', line 33

def increment_run_count!
  with_writable { update!(run_count: run_count + 1) }
end

#messageObject



41
42
43
44
# File 'lib/circuit_switch/orm/active_record/circuit_switch.rb', line 41

def message
  process = key == caller ? 'Watching process' : "Process for '#{key}'"
  "#{process} is called for #{report_count}th. Report until for #{report_limit_count}th."
end

#reached_report_limit?(new_value) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
# File 'lib/circuit_switch/orm/active_record/circuit_switch.rb', line 25

def reached_report_limit?(new_value)
  if new_value
    report_count >= new_value
  else
    report_count >= report_limit_count
  end
end

#reached_run_limit?(new_value) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
# File 'lib/circuit_switch/orm/active_record/circuit_switch.rb', line 17

def reached_run_limit?(new_value)
  if new_value
    run_count >= new_value
  else
    run_count >= run_limit_count
  end
end