Class: OkComputer::DelayedJobBackedUpCheck

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

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

Instance Method Summary collapse

Methods inherited from SizeThresholdCheck

#check

Methods inherited from Check

#clear, #mark_failure, #mark_message, #run, #success?, #to_json, #to_text

Constructor Details

#initialize(priority, threshold, options = {}) ⇒ DelayedJobBackedUpCheck

Public: Initialize a check for backed-up Delayed Job jobs

priority - Which priority to check for threshold - An Integer to compare the jobs count against

to consider it backed up

Example:

check = new(10, 50)
# => The check will look for jobs with priority between
# 0 and 10, considering the jobs as backed up if there
# are more than 50 of them


18
19
20
21
22
23
# File 'lib/ok_computer/built_in_checks/delayed_job_backed_up_check.rb', line 18

def initialize(priority, threshold, options = {})
  self.priority = Integer(priority)
  self.threshold = Integer(threshold)
  self.greater_than_priority = !!options[:greater_than_priority]
  self.name = greater_than_priority ? "Delayed Jobs with priority higher than '#{priority}'" : "Delayed Jobs with priority lower than '#{priority}'"
end

Instance Attribute Details

#greater_than_priorityObject

Returns the value of attribute greater_than_priority.



5
6
7
# File 'lib/ok_computer/built_in_checks/delayed_job_backed_up_check.rb', line 5

def greater_than_priority
  @greater_than_priority
end

#priorityObject

Returns the value of attribute priority.



3
4
5
# File 'lib/ok_computer/built_in_checks/delayed_job_backed_up_check.rb', line 3

def priority
  @priority
end

#thresholdObject

Returns the value of attribute threshold.



4
5
6
# File 'lib/ok_computer/built_in_checks/delayed_job_backed_up_check.rb', line 4

def threshold
  @threshold
end

Instance Method Details

#sizeObject

Public: How many delayed jobs are pending within the given priority



26
27
28
29
30
31
32
33
34
# File 'lib/ok_computer/built_in_checks/delayed_job_backed_up_check.rb', line 26

def size
  if defined?(::Delayed::Backend::Mongoid::Job) && Delayed::Worker.backend == Delayed::Backend::Mongoid::Job
    query = greater_than_priority ? Delayed::Job.gte(priority: priority) : Delayed::Job.lte(priority: priority)
  else
    operator = greater_than_priority ? ">=" : "<="
    query = Delayed::Job.where("priority #{operator} ?", priority)
  end
  query.where(:locked_at => nil, :last_error => nil).count
end