Class: OkComputer::SolidQueueScheduledBackedUpCheck

Inherits:
SizeThresholdCheck show all
Defined in:
lib/ok_computer/built_in_checks/solid_queue_scheduled_backed_up_check.rb

Overview

Detects a stalled SolidQueue dispatcher by counting scheduled jobs that are overdue — i.e. their scheduled_at is more than grace in the past, so a healthy dispatcher should already have promoted them to ready_executions.

This is distinct from SolidQueueBackedUpCheck, which measures ready (already promoted) depth. A dead/behind dispatcher leaves jobs stuck in scheduled and invisible to that check; this check surfaces them.

Constant Summary

Constants inherited from Check

Check::CheckNotDefined

Instance Attribute Summary collapse

Attributes inherited from SizeThresholdCheck

#name, #size_proc

Attributes inherited from Check

#failure_occurred, #message, #registrant_name, #skip_all, #time

Instance Method Summary collapse

Methods inherited from SizeThresholdCheck

#check

Methods inherited from Check

#<=>, #clear, #mark_failure, #mark_message, #run, #success?, #to_json, #to_text, #with_benchmarking

Constructor Details

#initialize(threshold, grace: 1.minute) ⇒ SolidQueueScheduledBackedUpCheck

Public: Initialize a check for overdue scheduled SolidQueue jobs

threshold - An Integer; the number of overdue scheduled jobs to tolerate before considering the dispatcher backed up. grace - An ActiveSupport::Duration; how far past scheduled_at a job must be before it counts as overdue. The dispatcher polls roughly every second (config/queue.yml polling_interval), so sub-poll lateness is normal and a grace window prevents flapping. Defaults to 1 minute.



21
22
23
24
25
# File 'lib/ok_computer/built_in_checks/solid_queue_scheduled_backed_up_check.rb', line 21

def initialize(threshold, grace: 1.minute)
  self.threshold = Integer(threshold)
  self.grace = grace
  self.name = "SolidQueue overdue scheduled jobs"
end

Instance Attribute Details

#graceObject

Returns the value of attribute grace.



11
12
13
# File 'lib/ok_computer/built_in_checks/solid_queue_scheduled_backed_up_check.rb', line 11

def grace
  @grace
end

#thresholdObject

Returns the value of attribute threshold.



10
11
12
# File 'lib/ok_computer/built_in_checks/solid_queue_scheduled_backed_up_check.rb', line 10

def threshold
  @threshold
end

Instance Method Details

#sizeObject

Public: Count of scheduled jobs overdue by more than grace. A healthy dispatcher keeps this at 0.



29
30
31
# File 'lib/ok_computer/built_in_checks/solid_queue_scheduled_backed_up_check.rb', line 29

def size
  SolidQueue::ScheduledExecution.where("scheduled_at <= ?", grace.ago).count
end