lib/bluepill/process.rb in bluepill-0.0.28 vs lib/bluepill/process.rb in bluepill-0.0.30
- old
+ new
@@ -27,11 +27,11 @@
:child_process_template
]
attr_accessor :name, :watches, :triggers, :logger, :skip_ticks_until
attr_accessor *CONFIGURABLE_ATTRIBUTES
- attr_reader :children
+ attr_reader :children, :statistics
state_machine :initial => :unmonitored do
# These are the idle states, i.e. only an event (either external or internal) will trigger a transition.
# The distinction between down and unmonitored is that down
# means we know it is not running and unmonitored is that we don't care if it's running.
@@ -89,10 +89,11 @@
@event_mutex = Monitor.new
@transition_history = Util::RotationalArray.new(10)
@watches = []
@triggers = []
@children = []
+ @statistics = ProcessStatistics.new
@monitor_children = options[:monitor_children] || false
%w(start_grace_time stop_grace_time restart_grace_time).each do |grace|
instance_variable_set("@#{grace}", options[grace.to_sym] || 3)
@@ -131,12 +132,13 @@
self.watches.each {|w| w.logger = logger }
self.triggers.each {|t| t.logger = logger }
end
# State machine methods
- def dispatch!(event)
+ def dispatch!(event, reason = nil)
@event_mutex.synchronize do
+ @statistics.record_event(event, reason)
self.send("#{event}")
end
end
def record_transition(transition)
@@ -179,16 +181,18 @@
threads.inject([]) do |events, (watch, thread)|
thread.join
if thread[:events].size > 0
logger.info "#{watch.name} dispatched: #{thread[:events].join(',')}"
- events << thread[:events]
+ thread[:events].each do |event|
+ events << [event, watch.to_s]
+ end
end
events
- end.flatten.uniq.each do |event|
+ end.each do |(event, reason)|
break if @transitioned
- self.dispatch!(event)
+ self.dispatch!(event, reason)
end
end
def handle_user_command(cmd)
case cmd
@@ -204,23 +208,23 @@
when "start"
if process_running?(true) && daemonize?
logger.warning("Refusing to re-run start command on an automatically daemonized process to preserve currently running process pid file.")
return
end
- dispatch!(:start)
+ dispatch!(:start, "user initiated")
when "stop"
stop_process
- dispatch!(:unmonitor)
+ dispatch!(:unmonitor, "user initiated")
when "restart"
restart_process
when "unmonitor"
# When the user issues an unmonitor cmd, reset any triggers so that
# scheduled events gets cleared
triggers.each {|t| t.reset! }
- dispatch!(:unmonitor)
+ dispatch!(:unmonitor, "user initiated")
end
end
# System Process Methods
def process_running?(force = false)
\ No newline at end of file