Class: SidekiqVigil::Checker
- Inherits:
-
Object
- Object
- SidekiqVigil::Checker
- Defined in:
- lib/sidekiq_vigil/checker.rb
Instance Attribute Summary collapse
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Instance Method Summary collapse
-
#initialize(storage:, config:, leader_election: nil, alert_manager: nil, notifier_manager: nil, logger: SidekiqVigil.logger, clock: -> { Time.now }, sleeper: ->(seconds) { sleep(seconds) }) ⇒ Checker
constructor
A new instance of Checker.
- #run_once ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(storage:, config:, leader_election: nil, alert_manager: nil, notifier_manager: nil, logger: SidekiqVigil.logger, clock: -> { Time.now }, sleeper: ->(seconds) { sleep(seconds) }) ⇒ Checker
Returns a new instance of Checker.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sidekiq_vigil/checker.rb', line 10 def initialize( storage:, config:, leader_election: nil, alert_manager: nil, notifier_manager: nil, logger: SidekiqVigil.logger, clock: -> { Time.now }, sleeper: ->(seconds) { sleep(seconds) } ) @storage = storage @config = config @logger = logger @clock = clock @sleeper = sleeper @leader_election = leader_election || LeaderElection.new(storage:, ttl: config.interval * 3) @notifier_manager = notifier_manager || build_notifier_manager @alert_manager = alert_manager || build_alert_manager @running = false @direct_redis_notified = false end |
Instance Attribute Details
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
8 9 10 |
# File 'lib/sidekiq_vigil/checker.rb', line 8 def thread @thread end |
Instance Method Details
#run_once ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/sidekiq_vigil/checker.rb', line 49 def run_once return false unless become_or_remain_leader results = configured_checks.flat_map(&:execute) events = alert_manager.process(results) write_snapshot(results) warn_config_drift notifier_manager.notify(events) @direct_redis_notified = false results rescue StandardError => e logger.error("[sidekiq-vigil] checker cycle failed: #{e.class}: #{e.}") notify_redis_outage(e) if redis_error?(e) false end |
#start ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/sidekiq_vigil/checker.rb', line 32 def start return thread if thread&.alive? @running = true @thread = Thread.new { run } @thread.name = "sidekiq-vigil-checker" if @thread.respond_to?(:name=) @thread end |
#stop ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/sidekiq_vigil/checker.rb', line 41 def stop @running = false thread&.wakeup if thread&.status == "sleep" thread&.join(config.interval + 1) leader_election.release @thread = nil end |