Class: QueuePulse::Checks::Failures

Inherits:
Base
  • Object
show all
Defined in:
lib/queue_pulse/checks/failures.rb

Overview

Detects newly failed jobs since the last pass using a high-water mark on solid_queue_failed_executions.id. On first ever run it establishes the baseline silently (so installing the gem doesn't replay history). Above failure_burst_threshold it collapses into a single summary alert. (Requirements US-2.)

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from QueuePulse::Checks::Base

Instance Method Details

#callObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/queue_pulse/checks/failures.rb', line 11

def call
  hwm = state.failed_high_water_mark

  if hwm.nil?
    baseline = source.max_failed_execution_id || 0
    state.set_failed_high_water_mark(baseline)
    return []
  end

  burst = config.failure_burst_threshold
  recent = source.failed_executions_since(hwm, limit: burst + 1)
  return [] if recent.empty?

  new_hwm = recent.map(&:id).max

  if recent.size > burst
    total = source.failed_count_since(hwm)
    state.set_failed_high_water_mark(source.max_failed_execution_id || new_hwm)
    [burst_alert(total)]
  else
    state.set_failed_high_water_mark(new_hwm)
    recent.map { |f| failure_alert(f) }
  end
end