Class: OkComputer::DelayedJobBackedUpCheck
- Inherits:
-
SizeThresholdCheck
- Object
- Check
- SizeThresholdCheck
- OkComputer::DelayedJobBackedUpCheck
- Defined in:
- lib/ok_computer/built_in_checks/delayed_job_backed_up_check.rb
Constant Summary
Constants inherited from Check
Instance Attribute Summary collapse
-
#greater_than_priority ⇒ Object
Returns the value of attribute greater_than_priority.
-
#include_errored ⇒ Object
Returns the value of attribute include_errored.
-
#include_locked ⇒ Object
Returns the value of attribute include_locked.
-
#priority ⇒ Object
Returns the value of attribute priority.
-
#queue ⇒ Object
Returns the value of attribute queue.
-
#threshold ⇒ Object
Returns the value of attribute threshold.
Attributes inherited from SizeThresholdCheck
Attributes inherited from Check
#failure_occurred, #message, #registrant_name, #time
Instance Method Summary collapse
-
#initialize(priority, threshold, options = {}) ⇒ DelayedJobBackedUpCheck
constructor
Public: Initialize a check for backed-up Delayed Job jobs.
-
#size ⇒ Object
Public: How many delayed jobs are pending within the given priority.
Methods inherited from SizeThresholdCheck
Methods inherited from Check
#<=>, #clear, #mark_failure, #mark_message, #run, #success?, #to_json, #to_text, #with_benchmarking
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 options - Hash of optional parameters
queue - Used to monitor a specific delayed job queue (default: nil)
include_locked - If true, will include currently locked jobs in the query (default: false)
include_errored - If true, will include currently errored jobs in the query (default: false)
greater_than_priority - If true, will include all jobs with a priority value equal or greater than the set value.
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
25 26 27 28 29 30 31 32 33 |
# File 'lib/ok_computer/built_in_checks/delayed_job_backed_up_check.rb', line 25 def initialize(priority, threshold, = {}) self.priority = Integer(priority) self.threshold = Integer(threshold) self.queue = [:queue] self.include_locked = !![:include_locked] self.include_errored = !![:include_errored] self.greater_than_priority = !![: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_priority ⇒ Object
Returns the value of attribute greater_than_priority.
3 4 5 |
# File 'lib/ok_computer/built_in_checks/delayed_job_backed_up_check.rb', line 3 def greater_than_priority @greater_than_priority end |
#include_errored ⇒ Object
Returns the value of attribute include_errored.
3 4 5 |
# File 'lib/ok_computer/built_in_checks/delayed_job_backed_up_check.rb', line 3 def include_errored @include_errored end |
#include_locked ⇒ Object
Returns the value of attribute include_locked.
3 4 5 |
# File 'lib/ok_computer/built_in_checks/delayed_job_backed_up_check.rb', line 3 def include_locked @include_locked end |
#priority ⇒ Object
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 |
#queue ⇒ Object
Returns the value of attribute queue.
3 4 5 |
# File 'lib/ok_computer/built_in_checks/delayed_job_backed_up_check.rb', line 3 def queue @queue end |
#threshold ⇒ Object
Returns the value of attribute threshold.
3 4 5 |
# File 'lib/ok_computer/built_in_checks/delayed_job_backed_up_check.rb', line 3 def threshold @threshold end |
Instance Method Details
#size ⇒ Object
Public: How many delayed jobs are pending within the given priority
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ok_computer/built_in_checks/delayed_job_backed_up_check.rb', line 36 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 opts = {} opts[:queue] = queue if queue opts[:locked_at] = nil unless include_locked opts[:last_error] = nil unless include_errored query.where(opts).count end |