Class: OkComputer::SolidQueueFailedJobsRateCheck

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

Overview

Detects rapid increases in failed SolidQueue jobs by counting failures that occurred within a rolling time window, rather than the total accumulated failures. This is stateless across requests: it relies on the created_at timestamp of each failed execution.

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, window = 300) ⇒ SolidQueueFailedJobsRateCheck

Public: Initialize a check for the rate of failing SolidQueue jobs

threshold - An Integer number of failures within the window to tolerate before the check is considered failed window - The size of the rolling window to count failures within. Accepts either a number of seconds or an ActiveSupport::Duration (e.g. 5.minutes). Defaults to 300 seconds (5 minutes).



17
18
19
20
21
# File 'lib/ok_computer/built_in_checks/solid_queue_failed_jobs_rate_check.rb', line 17

def initialize(threshold, window = 300)
  self.threshold = Integer(threshold)
  self.window = window
  self.name = "SolidQueue Failed Jobs Rate"
end

Instance Attribute Details

#thresholdObject

Returns the value of attribute threshold.



7
8
9
# File 'lib/ok_computer/built_in_checks/solid_queue_failed_jobs_rate_check.rb', line 7

def threshold
  @threshold
end

#windowObject

Returns the value of attribute window.



8
9
10
# File 'lib/ok_computer/built_in_checks/solid_queue_failed_jobs_rate_check.rb', line 8

def window
  @window
end

Instance Method Details

#sizeObject

Public: The number of jobs that have failed within the window



24
25
26
27
# File 'lib/ok_computer/built_in_checks/solid_queue_failed_jobs_rate_check.rb', line 24

def size
  cutoff = window.respond_to?(:ago) ? window.ago : Time.now - window
  SolidQueue::FailedExecution.where("created_at > ?", cutoff).count
end