MCPcopy Index your code
hub / github.com/cloudfoundry/cli / PollJobForState

Method PollJobForState

api/cloudcontroller/ccv3/job.go:101–147  ·  view source on GitHub ↗
(jobURL JobURL, state constant.JobState)

Source from the content-addressed store, hash-verified

99}
100
101func (client *Client) PollJobForState(jobURL JobURL, state constant.JobState) (Warnings, error) {
102 if jobURL == "" {
103 return nil, nil
104 }
105
106 var (
107 err error
108 warnings Warnings
109 allWarnings Warnings
110 job Job
111 )
112
113 startTime := client.clock.Now()
114 for client.clock.Now().Sub(startTime) < client.jobPollingTimeout {
115 job, warnings, err = client.GetJob(jobURL)
116 allWarnings = append(allWarnings, warnings...)
117 if err != nil {
118 return allWarnings, err
119 }
120
121 if job.HasFailed() {
122 if len(job.Errors()) > 0 {
123 firstError := job.Errors()[0]
124 return allWarnings, firstError
125 } else {
126 return allWarnings, ccerror.JobFailedNoErrorError{
127 JobGUID: job.GUID,
128 }
129 }
130 }
131
132 if job.IsComplete() {
133 return allWarnings, nil
134 }
135
136 if job.IsAt(state) {
137 return allWarnings, nil
138 }
139
140 time.Sleep(client.jobPollingInterval)
141 }
142
143 return allWarnings, ccerror.JobTimeoutError{
144 JobGUID: job.GUID,
145 Timeout: client.jobPollingTimeout,
146 }
147}
148
149type PollJobEvent struct {
150 State constant.JobState

Callers 1

PollJobMethod · 0.95

Calls 6

GetJobMethod · 0.95
HasFailedMethod · 0.80
ErrorsMethod · 0.80
IsCompleteMethod · 0.80
IsAtMethod · 0.80
NowMethod · 0.65

Tested by

no test coverage detected