Class: ProblemCheckTracker
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ProblemCheckTracker
- Defined in:
- app/models/problem_check_tracker.rb
Class Method Summary collapse
Instance Method Summary collapse
- #check ⇒ Object
- #failing? ⇒ Boolean
- #no_problem!(next_run_at: nil) ⇒ Object
- #passing? ⇒ Boolean
- #problem!(next_run_at: nil, details: {}) ⇒ Object
- #ready_to_run? ⇒ Boolean
- #reset(next_run_at: nil) ⇒ Object
Class Method Details
.[](identifier, target = ProblemCheck::NO_TARGET) ⇒ Object
10 11 12 |
# File 'app/models/problem_check_tracker.rb', line 10 def self.[](identifier, target = ProblemCheck::NO_TARGET) find_or_create_by(identifier:, target:) end |
Instance Method Details
#check ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/problem_check_tracker.rb', line 45 def check check = ProblemCheck[identifier] return check if check.present? silence_the_alarm destroy nil end |
#failing? ⇒ Boolean
18 19 20 |
# File 'app/models/problem_check_tracker.rb', line 18 def failing? last_problem_at == last_run_at end |
#no_problem!(next_run_at: nil) ⇒ Object
34 35 36 37 |
# File 'app/models/problem_check_tracker.rb', line 34 def no_problem!(next_run_at: nil) reset silence_the_alarm end |
#passing? ⇒ Boolean
22 23 24 |
# File 'app/models/problem_check_tracker.rb', line 22 def passing? last_success_at == last_run_at end |
#problem!(next_run_at: nil, details: {}) ⇒ Object
26 27 28 29 30 31 32 |
# File 'app/models/problem_check_tracker.rb', line 26 def problem!(next_run_at: nil, details: {}) now = Time.current update!(blips: blips + 1, details:, last_run_at: now, last_problem_at: now, next_run_at:) sound_the_alarm if sound_the_alarm? end |
#ready_to_run? ⇒ Boolean
14 15 16 |
# File 'app/models/problem_check_tracker.rb', line 14 def ready_to_run? next_run_at.blank? || next_run_at.past? end |
#reset(next_run_at: nil) ⇒ Object
39 40 41 42 43 |
# File 'app/models/problem_check_tracker.rb', line 39 def reset(next_run_at: nil) now = Time.current update!(blips: 0, last_run_at: now, last_success_at: now, next_run_at:) end |