From 61c222deb8602747e8d273252f14c7198166d2a1 Mon Sep 17 00:00:00 2001 From: Paulo Luis Franchini Casaretto Date: Wed, 17 Oct 2012 16:05:10 -0300 Subject: [PATCH] Add timeout switch to CLI --- lib/foreman/cli.rb | 1 + lib/foreman/engine.rb | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/foreman/cli.rb b/lib/foreman/cli.rb index 6ecf2c2a..6bf3461e 100644 --- a/lib/foreman/cli.rb +++ b/lib/foreman/cli.rb @@ -23,6 +23,7 @@ class Foreman::CLI < Thor method_option :env, :type => :string, :aliases => "-e", :desc => "Specify an environment file to load, defaults to .env" method_option :formation, :type => :string, :aliases => "-m", :banner => '"alpha=5,bar=3"' method_option :port, :type => :numeric, :aliases => "-p" + method_option :timeout, :type => :numeric, :aliases => "-t", :desc => "Specify the amount of time (in seconds) processes have to shudown gracefully before receiving a SIGKILL, defaults to 5." class << self # Hackery. Take the run method away from Thor so that we can redefine it. diff --git a/lib/foreman/engine.rb b/lib/foreman/engine.rb index 4d0fefa0..233ad29f 100644 --- a/lib/foreman/engine.rb +++ b/lib/foreman/engine.rb @@ -25,6 +25,7 @@ def initialize(options={}) @options = options.dup @options[:formation] ||= (options[:concurrency] || "all=1") + @options[:timeout] ||= 5 @env = {} @mutex = Mutex.new @@ -305,7 +306,7 @@ def terminate_gracefully system "sending SIGTERM to all processes" killall "SIGTERM" end - Timeout.timeout(5) do + Timeout.timeout(options[:timeout]) do watch_for_termination while @running.length > 0 end rescue Timeout::Error