forked from hashicorp/packer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployment_poller.go
48 lines (38 loc) · 989 Bytes
/
deployment_poller.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See the LICENSE file in builder/azure for license information.
package arm
import (
"time"
)
const (
DeployCanceled = "Canceled"
DeployFailed = "Failed"
DeployDeleted = "Deleted"
DeploySucceeded = "Succeeded"
)
type DeploymentPoller struct {
getProvisioningState func() (string, error)
pause func()
}
func NewDeploymentPoller(getProvisioningState func() (string, error)) *DeploymentPoller {
pollDuration := time.Second * 15
return &DeploymentPoller{
getProvisioningState: getProvisioningState,
pause: func() { time.Sleep(pollDuration) },
}
}
func (t *DeploymentPoller) PollAsNeeded() (string, error) {
for {
res, err := t.getProvisioningState()
if err != nil {
return res, err
}
switch res {
case DeployCanceled, DeployDeleted, DeployFailed, DeploySucceeded:
return res, nil
default:
break
}
t.pause()
}
}