Skip to content

Replace static sleep with datapoint polling after buzz add (on Client interface) #269

@narthur

Description

@narthur

Background

Originally implemented in #188, but that PR was built against the old package-level Beeminder API (CreateDatapoint(config, ...) returning *Datapoint, plus a top-level WaitForDatapoint). Main has since been refactored so all Beeminder calls are methods on the Client interface / HTTPClient in client.go, with context.Context threaded through. #188 conflicts irreconcilably with that refactor, so it was closed in favor of a clean re-implementation.

Goal

After buzz add, replace the static limsumFetchDelay sleep in main.go with polling that waits until the newly-added datapoint actually appears in the goal's recent data before showing the updated limsum.

Implementation notes (on current architecture)

  • Add a datapoint-returning create path: have CreateDatapoint / CreateDatapointWithDaystamp on the Client interface (and HTTPClient) return the created datapoint (or at least its ID) instead of only error. Update the fake client used in tests accordingly.
  • Add WaitForDatapoint(ctx, goalSlug, datapointID, timeout, pollInterval) to the Client interface, polling FetchGoalWithDatapoints until the ID appears or the timeout elapses.
  • Rewire messages.go (the buzz add submit path) to capture the created datapoint ID and poll instead of sleeping.
  • Remove limsumFetchDelay from main.go.
  • Carry over the edge cases handled in feat: replace static sleep with polling for datapoint verification after buzz add #188: zero/negative timeout still does at least one poll; fail fast on permanent errors (401/403/404) rather than retrying.
  • Update beeminder_test.go / handlers_test.go (now built around the fake client) to cover polling, permanent-error handling, and the zero-timeout case.

Reference

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions