Permalink
Browse files

Allow configurable process timeouts

If you know something is going to take a long time, just set a longer timeout.
  • Loading branch information...
1 parent 2c67b59 commit 8ad274de744a72cc2362120eea1945e147268904 @schneems schneems committed Mar 24, 2013
Showing with 12 additions and 7 deletions.
  1. +6 −2 README.md
  2. +2 −2 lib/hatchet/app.rb
  3. +4 −3 lib/hatchet/process_spawn.rb
View
8 README.md
@@ -71,7 +71,11 @@ It behaves exactly as if you were in a remote shell. If you really wanted you co
cmd.run("rake test")
-But since cmd.run doesn't return the exit status now, that wouldn't be so useful (also there is a default timeout to all commands).
+But since cmd.run doesn't return the exit status now, that wouldn't be
+so useful (also there is a default timeout to all commands). If you want
+you can configure the timeout by passing in a second parameter
+
+ cmd.run("rake test", 180.seconds)
## Testing A Different Buildpack
@@ -97,4 +101,4 @@ It would be great to allow hatchet to deploy apps off of git url, however if we
## Features?
-What else do we want to test? Config vars, addons, etc. Let's write some tests.
+What else do we want to test? Config vars, addons, etc. Let's write some tests.
View
4 lib/hatchet/app.rb
@@ -14,8 +14,8 @@ def git_repo
# runs a command on heroku similar to `$ heroku run #foo`
# but programatically and with more control
- def run(command, &block)
- ProcessSpawn.new(command, self).run(&block)
+ def run(command, timeout = nil, &block)
+ ProcessSpawn.new(command, self, timeout).run(&block)
end
# set debug: true when creating app if you don't want it to be
View
7 lib/hatchet/process_spawn.rb
@@ -3,13 +3,14 @@ module Hatchet
# spawns a process on Heroku, and keeps it open for writing
# like `heroku run bash`
class ProcessSpawn
- attr_reader :command, :app
+ attr_reader :command, :app, :timeout
TIMEOUT = 20 # seconds to bring up a heroku command like `heroku run bash`
- def initialize(command, app)
+ def initialize(command, app, timeout = nil)
@command = command
@app = app
+ @timeout = timeout || TIMEOUT
end
def ready?
@@ -35,7 +36,7 @@ def run(&block)
raise "need command" unless command.present?
output, input, pid = PTY.spawn("heroku run #{command} -a #{app.name}")
stream = StreamExec.new(input, output)
- stream.timeout("waiting for spawn", TIMEOUT) do
+ stream.timeout("waiting for spawn", timeout) do
wait_for_spawn!
end
raise "Could not run: #{command}" unless self.ready?

0 comments on commit 8ad274d

Please sign in to comment.