github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/actor/v7action/job.go (about) 1 package v7action 2 3 import ( 4 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" 5 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant" 6 ) 7 8 type JobState constant.JobState 9 10 const ( 11 JobPolling = JobState(constant.JobPolling) 12 JobComplete = JobState(constant.JobComplete) 13 JobFailed = JobState(constant.JobFailed) 14 JobProcessing = JobState(constant.JobProcessing) 15 ) 16 17 type PollJobEvent struct { 18 State JobState 19 Err error 20 Warnings Warnings 21 } 22 23 func (actor Actor) PollUploadBuildpackJob(jobURL ccv3.JobURL) (Warnings, error) { 24 warnings, err := actor.CloudControllerClient.PollJob(jobURL) 25 return Warnings(warnings), err 26 } 27 28 func (actor Actor) PollJobToEventStream(jobURL ccv3.JobURL) chan PollJobEvent { 29 input := actor.CloudControllerClient.PollJobToEventStream(jobURL) 30 if input == nil { 31 return nil 32 } 33 34 output := make(chan PollJobEvent) 35 36 go func() { 37 for event := range input { 38 output <- PollJobEvent{ 39 State: JobState(event.State), 40 Err: event.Err, 41 Warnings: Warnings(event.Warnings), 42 } 43 } 44 close(output) 45 }() 46 47 return output 48 }