forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.go
67 lines (53 loc) · 1.52 KB
/
build.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package v3action
import (
"errors"
"time"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
)
type Build ccv3.Build
type StagingTimeoutError struct {
AppName string
Timeout time.Duration
}
func (StagingTimeoutError) Error() string {
return "Timed out waiting for package to stage"
}
func (actor Actor) StagePackage(packageGUID string, appName string) (<-chan Build, <-chan Warnings, <-chan error) {
buildStream := make(chan Build)
warningsStream := make(chan Warnings)
errorStream := make(chan error)
go func() {
defer close(buildStream)
defer close(warningsStream)
defer close(errorStream)
build := ccv3.Build{Package: ccv3.Package{GUID: packageGUID}}
build, allWarnings, err := actor.CloudControllerClient.CreateBuild(build)
warningsStream <- Warnings(allWarnings)
if err != nil {
errorStream <- err
return
}
timeout := time.Now().Add(actor.Config.StagingTimeout())
for time.Now().Before(timeout) {
var warnings ccv3.Warnings
build, warnings, err = actor.CloudControllerClient.GetBuild(build.GUID)
warningsStream <- Warnings(warnings)
if err != nil {
errorStream <- err
return
}
switch build.State {
case ccv3.BuildStateFailed:
errorStream <- errors.New(build.Error)
return
case ccv3.BuildStateStaging:
time.Sleep(actor.Config.PollingInterval())
default:
buildStream <- Build(build)
return
}
}
errorStream <- StagingTimeoutError{AppName: appName, Timeout: actor.Config.StagingTimeout()}
}()
return buildStream, warningsStream, errorStream
}