You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Background
Originally implemented in #188, but that PR was built against the old package-level Beeminder API (
CreateDatapoint(config, ...)returning*Datapoint, plus a top-levelWaitForDatapoint). Main has since been refactored so all Beeminder calls are methods on theClientinterface /HTTPClientinclient.go, withcontext.Contextthreaded through. #188 conflicts irreconcilably with that refactor, so it was closed in favor of a clean re-implementation.Goal
After
buzz add, replace the staticlimsumFetchDelaysleep inmain.gowith 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)
CreateDatapoint/CreateDatapointWithDaystampon theClientinterface (andHTTPClient) return the created datapoint (or at least its ID) instead of onlyerror. Update the fake client used in tests accordingly.WaitForDatapoint(ctx, goalSlug, datapointID, timeout, pollInterval)to theClientinterface, pollingFetchGoalWithDatapointsuntil the ID appears or the timeout elapses.messages.go(thebuzz addsubmit path) to capture the created datapoint ID and poll instead of sleeping.limsumFetchDelayfrommain.go.beeminder_test.go/handlers_test.go(now built around the fake client) to cover polling, permanent-error handling, and the zero-timeout case.Reference