fetchJobWithBackoff polls the job resource until a PR number is present or the overall timeout elapses. It returns the updated Job on success, (nil, nil) on timeout, and (nil, error) only for non-retryable failures.
(ctx context.Context, client capi.CapiClient, repo ghrepo.Interface, jobID string, bo backoff.BackOff)
| 233 | // timeout elapses. It returns the updated Job on success, (nil, nil) on timeout, |
| 234 | // and (nil, error) only for non-retryable failures. |
| 235 | func fetchJobWithBackoff(ctx context.Context, client capi.CapiClient, repo ghrepo.Interface, jobID string, bo backoff.BackOff) (*capi.Job, error) { |
| 236 | // sentinel error to signal timeout |
| 237 | var errPRNotReady = errors.New("job not ready") |
| 238 | |
| 239 | var result *capi.Job |
| 240 | retryErr := backoff.Retry(func() error { |
| 241 | j, err := client.GetJob(ctx, repo.RepoOwner(), repo.RepoName(), jobID) |
| 242 | if err != nil { |
| 243 | // Do not retry on GetJob errors; surface immediately. |
| 244 | return backoff.Permanent(err) |
| 245 | } |
| 246 | if j.PullRequest != nil && j.PullRequest.Number > 0 { |
| 247 | result = j |
| 248 | return nil |
| 249 | } |
| 250 | return errPRNotReady |
| 251 | }, backoff.WithContext(bo, ctx)) |
| 252 | |
| 253 | if retryErr != nil { |
| 254 | if errors.Is(retryErr, errPRNotReady) { |
| 255 | // Timed out |
| 256 | return nil, nil |
| 257 | } |
| 258 | return nil, retryErr |
| 259 | } |
| 260 | return result, nil |
| 261 | } |
| 262 | |
| 263 | func followLogs(opts *CreateOptions, capiClient capi.CapiClient, sessionID string) error { |
| 264 | if err := opts.IO.StartPager(); err == nil { |
no test coverage detected