From 4a84a0c0d662654e893a21a4e412b959fa50c16c Mon Sep 17 00:00:00 2001 From: Tom Werner Date: Fri, 24 Aug 2007 14:12:24 -0700 Subject: [PATCH] start hot-load of watches functionality --- Manifest.txt | 1 + lib/god.rb | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Manifest.txt b/Manifest.txt index 8c10f26..0db9b7a 100644 --- a/Manifest.txt +++ b/Manifest.txt @@ -19,6 +19,7 @@ lib/god/conditions/memory_usage.rb lib/god/conditions/process_exits.rb lib/god/conditions/process_running.rb lib/god/conditions/timeline.rb +lib/god/conditions/tries.rb lib/god/errors.rb lib/god/event_handler.rb lib/god/event_handlers/dummy_handler.rb diff --git a/lib/god.rb b/lib/god.rb index cbb0a17..48cd981 100644 --- a/lib/god.rb +++ b/lib/god.rb @@ -47,7 +47,7 @@ module God VERSION = '0.3.0' class << self - attr_accessor :inited, :host, :port + attr_accessor :inited, :running, :host, :port # drb attr_accessor :server @@ -72,6 +72,9 @@ module God # init has been executed self.inited = true + + # not yet running + self.running = false end # Where pid files created by god will go by default @@ -92,6 +95,13 @@ module God w = Watch.new yield(w) + # if running, completely remove the watch (if necessary) to + # prepare for the reload + existing_watch = self.watches[w.name] + if self.running && existing_watch + self.unwatch(existing_watch) + end + # ensure the new watch has a unique name if self.watches[w.name] || self.groups[w.name] abort "Watch name '#{w.name}' already used for a Watch or Group" @@ -115,6 +125,19 @@ module God w.register! end + def self.unwatch(watch) + # unmonitor + watch.unmonitor + + # remove from watches + self.watches.delete(watch.name) + + # remove from groups + if watch.group + self.groups[watch.group].delete(watch) + end + end + def self.control(name, command) # get the list of watches watches = Array(self.watches[name] || self.groups[name]) @@ -151,6 +174,9 @@ module God # start monitoring any watches set to autostart self.watches.values.each { |w| w.monitor if w.autostart? } + # mark as running + self.running = true + # join the timer thread so we don't exit Timer.get.join end -- 2.11.4.GIT