]> CyberLeo.Net >> Repos - CDN/status.git/blob - lib/checks.rb
Naive parallelization of checks to reduce response time
[CDN/status.git] / lib / checks.rb
1 require 'configuration'
2 require 'check'
3 require 'database_check'
4 require 'website_check'
5
6
7 class Checks
8   @@config = "checks.yml"
9
10   def self.config
11     Configuration.load(@@config)
12   end
13
14   def initialize
15     @checks = []
16   end
17
18   def reload_config
19     return unless !@config || @config.stale?
20     @config ||= self.class.config
21     @checks = @config.map do |check|
22       Kernel.const_get(check[:class]).new(check)
23     end
24   end
25
26   def check
27     reload_config
28     threads = @checks.map {|check| Thread.new { check.do_it } }
29     threads.each(&:join)
30   end
31
32   def passed?
33     @checks.map(&:passed?).uniq == [ true ]
34   end
35
36   def results
37     @checks
38   end
39 end