From 409c7bf536bf14d49ea6512b5feedf0d26930b56 Mon Sep 17 00:00:00 2001 From: Tom Werner Date: Thu, 6 Sep 2007 13:00:44 -0700 Subject: [PATCH] add threading to remote commands --- bin/god | 4 +++- lib/god.rb | 12 ++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/bin/god b/bin/god index 13e0eb5..c4b0f56 100755 --- a/bin/god +++ b/bin/god @@ -154,12 +154,14 @@ elsif command = ARGV[0] begin puts "Sending '#{command}' command" - puts "This may take a few seconds depending on the grace periods assigned to your watches" + + t = Thread.new { loop { STDOUT.print('.'); STDOUT.flush; sleep(1) } } # send command watches = server.control(name, command) # output response + t.kill; STDOUT.puts puts 'The following watches were affected:' watches.each do |w| puts ' ' + w.name diff --git a/lib/god.rb b/lib/god.rb index e0f6772..bff49a7 100644 --- a/lib/god.rb +++ b/lib/god.rb @@ -176,20 +176,24 @@ module God # get the list of watches watches = Array(self.watches[name] || self.groups[name]) + jobs = [] + # do the command case command when "start", "monitor" - watches.each { |w| w.monitor } + watches.each { |w| jobs << Thread.new { w.monitor } } when "restart" - watches.each { |w| w.move(:restart) } + watches.each { |w| jobs << Thread.new { w.move(:restart) } } when "stop" - watches.each { |w| w.unmonitor.action(:stop) } + watches.each { |w| jobs << Thread.new { w.unmonitor.action(:stop) } } when "unmonitor" - watches.each { |w| w.unmonitor } + watches.each { |w| jobs << Thread.new { w.unmonitor } } else raise InvalidCommandError.new end + jobs.each { |j| j.join } + watches end -- 2.11.4.GIT