Skip to content

refactor: extract shared polling loop from GetGraph and GetCircularDependencies in api/client.go #41

@claude

Description

@claude

GetGraph (lines 265–397) and GetCircularDependencies (lines 399–534) in internal/api/client.go each contain ~130 lines of near-identical async polling logic. Both methods:

  • Build a multipart request body
  • Generate an idempotency key
  • Poll in a loop, checking ctx.Done(), a deadline, and maxPollAttempts
  • Handle HTTP status codes identically (401, 402, 429, 404/405, 200/202, default)
  • Parse a JobStatus envelope and branch on completed / failed / pending / processing
  • Sleep for retryAfter seconds between attempts

Only the endpoint URL and the result-parsing step differ.

Impact

Any change to retry behavior, backoff, or error handling must be made in two places. This has already diverged subtly (e.g. 404/405 is only handled in GetCircularDependencies).

Proposed Fix

Extract a pollJob helper that accepts endpoint URL, the pre-built multipart body/content-type, and a parseResult func(*json.RawMessage) error callback. Both public methods become thin wrappers:

func (c *Client) pollJob(
    ctx context.Context,
    endpoint string,
    bodyBytes []byte,
    contentType string,
    idempotencyKey string,
    onComplete func(*json.RawMessage) error,
    notFound func() error,
) error

Files

  • internal/api/client.go lines 265–534

@claude please implement this

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions