Class: IsItWorking::Filter
- Inherits:
-
Object
- Object
- IsItWorking::Filter
- Defined in:
- lib/is_it_working/filter.rb
Overview
Wrapper around a status check.
Defined Under Namespace
Classes: AsyncRunner, SyncRunner
Instance Attribute Summary collapse
-
#async ⇒ Object
readonly
Returns the value of attribute async.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.run_filters(filters) ⇒ Object
Run a list of filters and return their status objects.
Instance Method Summary collapse
-
#initialize(name, check, async = true) ⇒ Filter
constructor
Create a new filter to run a status check.
-
#run ⇒ Object
Run a status the status check.
Constructor Details
#initialize(name, check, async = true) ⇒ Filter
Create a new filter to run a status check. The name is used for display purposes.
22 23 24 25 26 |
# File 'lib/is_it_working/filter.rb', line 22 def initialize(name, check, async = true) @name = name @check = check @async = async end |
Instance Attribute Details
#async ⇒ Object (readonly)
Returns the value of attribute async.
19 20 21 |
# File 'lib/is_it_working/filter.rb', line 19 def async @async end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/is_it_working/filter.rb', line 19 def name @name end |
Class Method Details
.run_filters(filters) ⇒ Object
Run a list of filters and return their status objects
47 48 49 50 51 52 |
# File 'lib/is_it_working/filter.rb', line 47 def run_filters (filters) runners = filters.collect{|f| f.run} statuses = runners.collect{|runner| runner.filter_status} runners.each{|runner| runner.join} statuses end |
Instance Method Details
#run ⇒ Object
Run a status the status check. This method keeps track of the time it took to run the check and will trap any unexpected exceptions and report them as failures.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/is_it_working/filter.rb', line 30 def run status = Status.new(name) runner = (async ? AsyncRunner : SyncRunner).new do t = Time.now begin @check.call(status) rescue Exception => e status.fail("#{name} error: #{e.inspect}") end status.time = Time.now - t end runner.filter_status = status runner end |