~ubuntu-branches/ubuntu/saucy/juju-core/saucy-updates

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/environs/polling.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-09-03 14:22:22 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20130903142222-9mes2r8wqr0bs7lp
Tags: 1.13.3-0ubuntu1
New upstream point release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2013 Canonical Ltd.
2
 
// Licensed under the AGPLv3, see LICENCE file for details.
3
 
 
4
 
package environs
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
 
}