Permalink
Browse files

add rdoc plus start of times support

  • Loading branch information...
1 parent 81db55e commit de713350488e741ba00372500c0af86d16ccd70e Steven Jenkins committed Oct 4, 2010
Showing with 60 additions and 1 deletion.
  1. +60 −1 lib/god/conditions/socket_responding.rb
@@ -3,8 +3,50 @@
module God
module Conditions
+ # Condition Symbol :socket_running
+ # Type: Poll
+ #
+ # Trigger when a TCP or UNIX socket is running or not
+ #
+ # Parameters
+ # Required
+ # +family+ is the family of socket: either 'tcp' or 'unix'
+ # +port+ is the port (required if +family+ is 'tcp')
+ # +path+ is the path (required if +family+ is 'unix')
+ #
+ # Examples
+ #
+ # Trigger if the TCP socket on port 80 is not responding or the connection is refused
+ #
+ # on.condition(:socket_responding) do |c|
+ # c.family = 'tcp'
+ # c.port = '80'
+ # end
+ #
+ # Trigger if the socket is not responding or the connection is refused (use alternate compact +socket+ interface)
+ #
+ # on.condition(:socket_responding) do |c|
+ # c.socket = 'tcp:80'
+ # end
+ #
+ # Trigger if the socket is not responding or the connection is refused 5 times in a row
+ #
+ # on.condition(:socket_responding) do |c|
+ # c.socket = 'tcp:80'
+ # c.times = 5
+ # end
+ #
+ # Trigger if the Unix socket on path '/tmp/sock' is not responding or non-existent
+ #
+ # on.condition(:socket_responding) do |c|
+ # c.family = 'unix'
+ # c.port = '/tmp/sock'
+ # end
+ #
+
+
class SocketResponding < PollCondition
- attr_accessor :family, :addr, :port, :path
+ attr_accessor :family, :addr, :port, :path, :times
def initialize
super
@@ -14,8 +56,24 @@ def initialize
# Set these to nil/0 values
self.port = 0
self.path = nil
+
+ self.times = [1, 1]
end
+ def prepare
+ if self.times.kind_of?(Integer)
+ self.times = [self.times, self.times]
+ end
+
+ @timeline = Timeline.new(self.times[1])
+ @history = Timeline.new(self.times[1])
+ end
+
+ def reset
+ @timeline.clear
+ @history.clear
+ end
+
def socket=(s)
components = s.split(':')
if components.size == 3
@@ -38,6 +96,7 @@ def valid?
if self.family == 'unix' and self.path.nil?
valid &= complain("Attribute 'path' must be specified for unix sockets", self)
end
+ valid = false unless %w{tcp unix}.match(self.family)
valid
end

0 comments on commit de71335

Please sign in to comment.