github.com/cloudbase/juju-core@v0.0.0-20140504232958-a7271ac7912f/provider/common/polling.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package common 5 6 import ( 7 "fmt" 8 "time" 9 10 "launchpad.net/juju-core/instance" 11 "launchpad.net/juju-core/utils" 12 ) 13 14 // Use ShortAttempt to poll for short-term events. 15 // TODO: This may need tuning for different providers (or even environments). 16 var ShortAttempt = utils.AttemptStrategy{ 17 Total: 5 * time.Second, 18 Delay: 200 * time.Millisecond, 19 } 20 21 // A request may fail to due "eventual consistency" semantics, which 22 // should resolve fairly quickly. These delays are specific to the provider 23 // and best tuned there. 24 // Other requests fail due to a slow state transition (e.g. an instance taking 25 // a while to release a security group after termination). If you need to 26 // poll for the latter kind, use LongAttempt. 27 var LongAttempt = utils.AttemptStrategy{ 28 Total: 3 * time.Minute, 29 Delay: 1 * time.Second, 30 } 31 32 // WaitDNSName is an implementation that the providers can use. It builds on 33 // the provider's implementation of Instance.DNSName. 34 func WaitDNSName(inst instance.Instance) (string, error) { 35 for a := LongAttempt.Start(); a.Next(); { 36 name, err := inst.DNSName() 37 if err == nil || err != instance.ErrNoDNSName { 38 return name, err 39 } 40 } 41 return "", fmt.Errorf("timed out trying to get DNS address for %v", inst.Id()) 42 }