Class: OkComputer::Check
- Inherits:
-
Object
- Object
- OkComputer::Check
- Defined in:
- lib/ok_computer/check.rb
Direct Known Subclasses
ActiveRecordCheck, AppVersionCheck, CacheCheck, DefaultCheck, DirectoryCheck, GenericCacheCheck, HttpCheck, MongoidCheck, MongoidReplicaSetCheck, Neo4jCheck, PingCheck, RabbitmqCheck, RedisCheck, ResqueDownCheck, RubyVersionCheck, SizeThresholdCheck
Constant Summary collapse
- CheckNotDefined =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#failure_occurred ⇒ Object
nil by default, only set to true if the check deems itself failed.
-
#message ⇒ Object
nil by default, set by #check to control the output.
-
#registrant_name ⇒ Object
to be set by Registry upon registration.
-
#time ⇒ Object
Float::NAN by default, set by #run to the elapsed time to run #check.
Instance Method Summary collapse
- #<=>(check) ⇒ Object
-
#clear ⇒ Object
Public: Clear any prior failures.
-
#mark_failure ⇒ Object
Public: Mark that this check has failed in some way.
-
#mark_message(message) ⇒ Object
Public: Capture the desired message to display.
-
#run ⇒ Object
Public: Run the check.
-
#success? ⇒ Boolean
Public: Whether the check passed.
-
#to_json(*args) ⇒ Object
Public: The JSON output of performing the check.
-
#to_text ⇒ Object
Public: The text output of performing the check.
-
#with_benchmarking ⇒ Object
Private: Benchmark the time it takes to run the block.
Instance Attribute Details
#failure_occurred ⇒ Object
nil by default, only set to true if the check deems itself failed
8 9 10 |
# File 'lib/ok_computer/check.rb', line 8 def failure_occurred @failure_occurred end |
#message ⇒ Object
nil by default, set by #check to control the output
10 11 12 |
# File 'lib/ok_computer/check.rb', line 10 def @message end |
#registrant_name ⇒ Object
to be set by Registry upon registration
6 7 8 |
# File 'lib/ok_computer/check.rb', line 6 def registrant_name @registrant_name end |
#time ⇒ Object
Float::NAN by default, set by #run to the elapsed time to run #check
12 13 14 |
# File 'lib/ok_computer/check.rb', line 12 def time @time end |
Instance Method Details
#<=>(check) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/ok_computer/check.rb', line 48 def <=>(check) if check.is_a?(CheckCollection) -1 else registrant_name <=> check.registrant_name end end |
#clear ⇒ Object
Public: Clear any prior failures
76 77 78 79 80 |
# File 'lib/ok_computer/check.rb', line 76 def clear self.failure_occurred = false self. = nil self.time = Float::NAN end |
#mark_failure ⇒ Object
Public: Mark that this check has failed in some way
64 65 66 |
# File 'lib/ok_computer/check.rb', line 64 def mark_failure self.failure_occurred = true end |
#mark_message(message) ⇒ Object
Public: Capture the desired message to display
message - Text of the message to display for this check
71 72 73 |
# File 'lib/ok_computer/check.rb', line 71 def () self. = end |
#run ⇒ Object
Public: Run the check
15 16 17 18 19 20 |
# File 'lib/ok_computer/check.rb', line 15 def run clear with_benchmarking do check end end |
#success? ⇒ Boolean
Public: Whether the check passed
Returns a boolean
59 60 61 |
# File 'lib/ok_computer/check.rb', line 59 def success? not failure_occurred end |
#to_json(*args) ⇒ Object
Public: The JSON output of performing the check
Returns a String containing JSON
42 43 44 45 46 |
# File 'lib/ok_computer/check.rb', line 42 def to_json(*args) # NOTE swallowing the arguments that Rails passes by default since we don't care. This may prove to be a bad idea # Rails passes stuff like this: {:prefixes=>["ok_computer", "application"], :template=>"show", :layout=>#<Proc>}] {registrant_name => {:message => , :success => success?, :time => time}}.to_json end |
#to_text ⇒ Object
Public: The text output of performing the check
Returns a String
34 35 36 37 |
# File 'lib/ok_computer/check.rb', line 34 def to_text passfail = success? ? "passed" : "failed" I18n.t("okcomputer.check.#{passfail}", registrant_name: registrant_name, message: , time: "#{time ? sprintf('%0.000f', time) : '?'}s") end |
#with_benchmarking ⇒ Object
Private: Benchmark the time it takes to run the block
83 84 85 86 87 |
# File 'lib/ok_computer/check.rb', line 83 def with_benchmarking self.time = Benchmark.realtime do yield end end |