Class: IsItWorking::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/is_it_working/filter.rb

Overview

Wrapper around a status check.

Defined Under Namespace

Classes: AsyncRunner, SyncRunner

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#asyncObject (readonly)

Returns the value of attribute async.



19
20
21
# File 'lib/is_it_working/filter.rb', line 19

def async
  @async
end

#nameObject (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

#runObject

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