Class: OkComputer::SizeThresholdCheck
- Defined in:
- lib/ok_computer/built_in_checks/size_threshold_check.rb
Direct Known Subclasses
DelayedJobBackedUpCheck, ResqueBackedUpCheck, ResqueFailureThresholdCheck, SidekiqLatencyCheck
Constant Summary
Constants inherited from Check
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#size_proc ⇒ Object
Returns the value of attribute size_proc.
-
#threshold ⇒ Object
Returns the value of attribute threshold.
Attributes inherited from Check
#failure_occurred, #message, #registrant_name, #time
Instance Method Summary collapse
-
#check ⇒ Object
Public: Check whether the given queue is backed up.
-
#initialize(name, threshold, &size_proc) ⇒ SizeThresholdCheck
constructor
Public: Initialize a check for a backed-up Resque queue.
-
#size ⇒ Object
Public: The number of jobs in the check’s queue.
Methods inherited from Check
#<=>, #clear, #mark_failure, #mark_message, #run, #success?, #to_json, #to_text, #with_benchmarking
Constructor Details
#initialize(name, threshold, &size_proc) ⇒ SizeThresholdCheck
Public: Initialize a check for a backed-up Resque queue
name - the value that this check should be refered to as threshold - An Integer to compare the size object’s count against to consider
it backed up
size_proc - The block/proc that returns an integer to compare against
Examples
SizeThresholdCheck.new("some queue", 2) do
Queue.new("my_queue").size
end
20 21 22 23 24 |
# File 'lib/ok_computer/built_in_checks/size_threshold_check.rb', line 20 def initialize(name, threshold, &size_proc) self.size_proc = size_proc self.threshold = Integer(threshold) self.name = name end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/ok_computer/built_in_checks/size_threshold_check.rb', line 5 def name @name end |
#size_proc ⇒ Object
Returns the value of attribute size_proc.
3 4 5 |
# File 'lib/ok_computer/built_in_checks/size_threshold_check.rb', line 3 def size_proc @size_proc end |
#threshold ⇒ Object
Returns the value of attribute threshold.
4 5 6 |
# File 'lib/ok_computer/built_in_checks/size_threshold_check.rb', line 4 def threshold @threshold end |
Instance Method Details
#check ⇒ Object
Public: Check whether the given queue is backed up
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ok_computer/built_in_checks/size_threshold_check.rb', line 27 def check # Memoize size here to prevent a theoretically # expensive operation from happening more than once size = self.size if size <= threshold "#{name} at reasonable level (#{size})" else mark_failure "#{name} is #{size - threshold} over threshold! (#{size})" end rescue ArgumentError, TypeError => e mark_failure "The given proc MUST return a number (#{e.class})" rescue StandardError => e mark_failure "An error occurred: '#{e.}' (#{e.class})" end |
#size ⇒ Object
Public: The number of jobs in the check’s queue
46 47 48 |
# File 'lib/ok_computer/built_in_checks/size_threshold_check.rb', line 46 def size Integer(size_proc.call) end |