Skip to content

Commit

Permalink
Added timeout for AWS requests (10 seconds)
Browse files Browse the repository at this point in the history
  • Loading branch information
delano committed Apr 7, 2009
1 parent c1d298b commit d7ca057
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 58 deletions.
59 changes: 4 additions & 55 deletions Rudyfile
Expand Up @@ -47,68 +47,17 @@ machines do
end

end
end

env :gateway do

role :gateway do

end
end

end

networks do
# simple_gateway, server-connections.yml:
# ---
# local:
# - foo
# foo:
# - bar
# - baz
# bar:
# - foobar
# - foobaz
# - barbaz
end


# ------------------------------------------------------- ROUTINES --------
# The routines block describe processes for each machine group.
routines do

env :stage do
role :app do

shutdown do
before :root => "echo 'BEFORE' && pwd"
disks do
destroy "/rudy/example1"
destroy "/rudy/example2"
end
end

startup do
disks do
create "/rudy/example1" do
device "/dev/sdl"
end
create "/rudy/example2"
end

after :root => "pwd"
after :rudy => "pwd"
end

restart do
before :root => "pwd"
after :root => "pwd"
after :rudy => "pwd"

disks do
mount "/rudy/example1"
mount "/rudy/example2"
end
end

end
end

end

12 changes: 9 additions & 3 deletions lib/rudy/aws.rb
Expand Up @@ -27,22 +27,28 @@ def initialize(aws_connection)


protected

# Execute AWS requests safely. This will trap errors and return
# a default value (if specified).
# * +default+ A default response value
# * +request+ A block which contains the AWS request
# Returns the return value from the request is returned untouched
# or the default value on error or if the request returned nil.
def execute_request(default=nil, &request)
def execute_request(default=nil, timeout=nil, &request)
timeout ||= 10
raise "No block provided" unless request
response = nil
begin
response = request.call
Timeout::timeout(timeout) do
response = request.call
end
rescue ::EC2::Error => ex
STDERR.puts ex.message
rescue ::EC2::InvalidInstanceIDMalformed => ex
STDERR.puts ex.message
rescue Timeout::Error => ex
STDERR.puts "Timeout (#{timeout}): #{ex.message}!"
false
ensure
response ||= default
end
Expand Down

0 comments on commit d7ca057

Please sign in to comment.