From b9c6139d6732552a4e00afd310de28bddbc4688f Mon Sep 17 00:00:00 2001 From: Ganesh kumar Sankaran Date: Fri, 28 Oct 2016 00:28:12 -0700 Subject: [PATCH] AWS async operations sometimes takes long times, if there are multiple parallel builds, polling at 2 second frequency will exceed the request limit. Allow 2 seconds to be overwritten with AWS_POLL_DELAY_SECONDS --- builder/amazon/common/state.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/builder/amazon/common/state.go b/builder/amazon/common/state.go index 9c2630445..f83df5f5b 100644 --- a/builder/amazon/common/state.go +++ b/builder/amazon/common/state.go @@ -162,7 +162,7 @@ func ImportImageRefreshFunc(conn *ec2.EC2, importTaskId string) StateRefreshFunc func WaitForState(conf *StateChangeConf) (i interface{}, err error) { log.Printf("Waiting for state to become: %s", conf.Target) - sleepSeconds := 2 + sleepSeconds := SleepSeconds() maxTicks := int(TimeoutSeconds()/sleepSeconds) + 1 notfoundTick := 0 @@ -239,3 +239,24 @@ func TimeoutSeconds() (seconds int) { log.Printf("Allowing %ds to complete (change with AWS_TIMEOUT_SECONDS)", seconds) return seconds } + +// Returns 2 seconds by default +// AWS async operations sometimes takes long times, if there are multiple parallel builds, +// polling at 2 second frequency will exceed the request limit. Allow 2 seconds to be +// overwritten with AWS_POLL_DELAY_SECONDS +func SleepSeconds() (seconds int) { + seconds = 2 + + override := os.Getenv("AWS_POLL_DELAY_SECONDS") + if override != "" { + n, err := strconv.Atoi(override) + if err != nil { + log.Printf("Invalid timeout seconds '%s', using default", override) + } else { + seconds = n + } + } + + log.Printf("Using %ds as polling delay (change with AWS_POLL_DELAY_SECONDS)", seconds) + return seconds +}