Merge pull request #8370 from hashicorp/dtolnoy-wait
Do not sleep between first attempt or between successful attempts
This commit is contained in:
commit
6ae7140251
|
@ -2,7 +2,6 @@ package resource
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"math"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -72,16 +71,16 @@ func (conf *StateChangeConf) WaitForState() (interface{}, error) {
|
||||||
// Wait for the delay
|
// Wait for the delay
|
||||||
time.Sleep(conf.Delay)
|
time.Sleep(conf.Delay)
|
||||||
|
|
||||||
|
wait := 100 * time.Millisecond
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
var wait time.Duration
|
for first := true; ; first = false {
|
||||||
for tries := 0; ; tries++ {
|
if !first {
|
||||||
// Wait between refreshes using an exponential backoff
|
// If a poll interval has been specified, choose that interval.
|
||||||
// If a poll interval has been specified, choose that interval
|
// Otherwise bound the default value.
|
||||||
if conf.PollInterval > 0 && conf.PollInterval < 180*time.Second {
|
if conf.PollInterval > 0 && conf.PollInterval < 180*time.Second {
|
||||||
wait = conf.PollInterval
|
wait = conf.PollInterval
|
||||||
} else {
|
} else {
|
||||||
wait = time.Duration(math.Pow(2, float64(tries))) *
|
|
||||||
100 * time.Millisecond
|
|
||||||
if wait < conf.MinTimeout {
|
if wait < conf.MinTimeout {
|
||||||
wait = conf.MinTimeout
|
wait = conf.MinTimeout
|
||||||
} else if wait > 10*time.Second {
|
} else if wait > 10*time.Second {
|
||||||
|
@ -92,6 +91,13 @@ func (conf *StateChangeConf) WaitForState() (interface{}, error) {
|
||||||
log.Printf("[TRACE] Waiting %s before next try", wait)
|
log.Printf("[TRACE] Waiting %s before next try", wait)
|
||||||
time.Sleep(wait)
|
time.Sleep(wait)
|
||||||
|
|
||||||
|
// Wait between refreshes using exponential backoff, except when
|
||||||
|
// waiting for the target state to reoccur.
|
||||||
|
if targetOccurence == 0 {
|
||||||
|
wait *= 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var currentState string
|
var currentState string
|
||||||
result, currentState, err = conf.Refresh()
|
result, currentState, err = conf.Refresh()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue