lib/eye/checker.rb in reel-eye-0.4 vs lib/eye/checker.rb in reel-eye-0.4.1
- old
+ new
@@ -4,20 +4,22 @@
autoload :Cpu, 'eye/checker/cpu'
autoload :Http, 'eye/checker/http'
autoload :FileCTime, 'eye/checker/file_ctime'
autoload :FileSize, 'eye/checker/file_size'
autoload :Socket, 'eye/checker/socket'
+ autoload :Nop, 'eye/checker/nop'
TYPES = {:memory => "Memory", :cpu => "Cpu", :http => "Http",
- :ctime => "FileCTime", :fsize => "FileSize", :socket => "Socket"}
+ :ctime => "FileCTime", :fsize => "FileSize", :socket => "Socket",
+ :nop => "Nop" }
attr_accessor :value, :values, :options, :pid, :type, :check_count, :process
extend Eye::Dsl::Validation
param :every, [Fixnum, Float], false, 5
param :times, [Fixnum, Array], nil, 1
- param :fire, Symbol, nil, nil, [:stop, :restart, :unmonitor, :nothing]
+ param :fires, [Symbol, Array], nil, nil, [:stop, :restart, :unmonitor, :nothing, :start, :delete]
def self.name_and_class(type)
type = type.to_sym
return {:name => type, :type => type} if TYPES[type]
@@ -33,10 +35,14 @@
klass
end
def self.create(pid, options = {}, process = nil)
get_class(options[:type]).new(pid, options, process)
+
+ rescue Exception, Timeout::Error => ex
+ log_ex(ex)
+ nil
end
def self.validate!(options)
get_class(options[:type]).validate(options)
end
@@ -44,20 +50,21 @@
def initialize(pid, options = {}, process = nil)
@process = process
@pid = pid
@options = options
@type = options[:type]
+ @full_name = @process.full_name if @process
debug "create checker, with #{options}"
@value = nil
@values = Eye::Utils::Tail.new(max_tries)
@check_count = 0
end
def inspect
- "<#{self.class} @process='#{@process.full_name}' @options=#{@options} @pid=#{@pid}>"
+ "<#{self.class} @process='#{@full_name}' @options=#{@options} @pid=#{@pid}>"
end
def logger_tag
@process.logger.prefix
end
@@ -87,10 +94,13 @@
result = false if bad_count >= min_tries
end
info "#{last_human_values} => #{result ? 'OK' : 'Fail'}"
result
+
+ rescue Exception, Timeout::Error => ex
+ log_ex(ex)
end
def get_value_safe
get_value
end
@@ -160,10 +170,17 @@
type = name.underscore.to_sym
Eye::Checker::TYPES[type] = name
Eye::Checker.const_set(name, base)
end
- class Custom < Eye::Checker
+ class CustomCell < Eye::Checker
+ def self.inherited(base)
+ super
+ register(base)
+ end
+ end
+
+ class Custom < Defer
def self.inherited(base)
super
register(base)
end
end