github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/actor/v3action/build.go (about) 1 package v3action 2 3 import ( 4 "errors" 5 "time" 6 7 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" 8 ) 9 10 type StagingTimeoutError struct { 11 AppName string 12 Timeout time.Duration 13 } 14 15 func (StagingTimeoutError) Error() string { 16 return "Timed out waiting for package to stage" 17 } 18 19 func (actor Actor) StagePackage(packageGUID string, appName string) (<-chan Droplet, <-chan Warnings, <-chan error) { 20 dropletStream := make(chan Droplet) 21 warningsStream := make(chan Warnings) 22 errorStream := make(chan error) 23 24 go func() { 25 defer close(dropletStream) 26 defer close(warningsStream) 27 defer close(errorStream) 28 29 build := ccv3.Build{PackageGUID: packageGUID} 30 build, allWarnings, err := actor.CloudControllerClient.CreateBuild(build) 31 warningsStream <- Warnings(allWarnings) 32 33 if err != nil { 34 errorStream <- err 35 return 36 } 37 38 timeout := time.Now().Add(actor.Config.StagingTimeout()) 39 40 for time.Now().Before(timeout) { 41 var warnings ccv3.Warnings 42 build, warnings, err = actor.CloudControllerClient.GetBuild(build.GUID) 43 warningsStream <- Warnings(warnings) 44 if err != nil { 45 errorStream <- err 46 return 47 } 48 49 switch build.State { 50 case ccv3.BuildStateFailed: 51 errorStream <- errors.New(build.Error) 52 return 53 case ccv3.BuildStateStaging: 54 time.Sleep(actor.Config.PollingInterval()) 55 default: 56 57 //TODO: uncommend after #150569020 58 // ccv3Droplet, warnings, err := actor.CloudControllerClient.GetDroplet(build.DropletGUID) 59 // warningsStream <- Warnings(warnings) 60 // if err != nil { 61 // errorStream <- err 62 // return 63 // } 64 65 ccv3Droplet := ccv3.Droplet{ 66 GUID: build.DropletGUID, 67 State: ccv3.DropletState(build.State), 68 CreatedAt: build.CreatedAt, 69 } 70 71 dropletStream <- actor.convertCCToActorDroplet(ccv3Droplet) 72 return 73 } 74 } 75 76 errorStream <- StagingTimeoutError{AppName: appName, Timeout: actor.Config.StagingTimeout()} 77 }() 78 79 return dropletStream, warningsStream, errorStream 80 }