MCPcopy Index your code
hub / github.com/cli/cli / fetchJobWithBackoff

Function fetchJobWithBackoff

pkg/cmd/agent-task/create/create.go:235–261  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

233// timeout elapses. It returns the updated Job on success, (nil, nil) on timeout,
234// and (nil, error) only for non-retryable failures.
235func 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
263func followLogs(opts *CreateOptions, capiClient capi.CapiClient, sessionID string) error {
264 if err := opts.IO.StartPager(); err == nil {

Callers 1

fetchJobSessionURLFunction · 0.85

Calls 3

GetJobMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65

Tested by

no test coverage detected