Skip to content

Commit

Permalink
Merge pull request #277 from pcasaretto/add-timeout-switch
Browse files Browse the repository at this point in the history
Add timeout switch to CLI - fixes #178
  • Loading branch information
ddollar committed Jan 14, 2013
2 parents bb2c3a2 + 61c222d commit 4400295
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/foreman/cli.rb
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion lib/foreman/engine.rb
Expand Up @@ -25,6 +25,7 @@ def initialize(options={})
@options = options.dup

@options[:formation] ||= (options[:concurrency] || "all=1")
@options[:timeout] ||= 5

@env = {}
@mutex = Mutex.new
Expand Down Expand Up @@ -312,7 +313,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
Expand Down

1 comment on commit 4400295

@TheDeveloper
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.