fix: auto-fetch all SleepHQ history in 30-day batches with 90s delay#98
Draft
camden-bock wants to merge 3 commits into
Draft
fix: auto-fetch all SleepHQ history in 30-day batches with 90s delay#98camden-bock wants to merge 3 commits into
camden-bock wants to merge 3 commits into
Conversation
The sleephq-client library defaults to scope='read write delete', but SleepHQ OAuth apps may only authorize read access. Explicitly request scope='read' to match the importer's read-only data flow. Also document this in the UI settings description so users know no data is written or deleted on SleepHQ.
The frontend had no UI control for lookback_days, so the DB default of 30 was always used. Add a number input in the SleepHQ settings card and include it in the save payload so users can configure how many days of history to fetch on import.
Replaces the configurable lookback_days with an automatic full-history walk that discovers the extent of SleepHQ data by fetching successive 30-day windows with a 90-second pause between batches. - Add fetch_all_machine_dates() that walks backwards from today in 30-day windows with _BATCH_DELAY=90s between each batch - run_sleephq_import auto-selects full walk when no explicit date range is given (CLI path unchanged) - Remove lookback_days from the server trigger path and frontend Settings UI since it no longer applies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
lookback_dayscontrol and the DB defaulted to 30.read write deleteOAuth scopes, but SleepHQ OAuth apps may only authorizereadaccess.Changes
importer/sleephq_import.py— Addedfetch_all_machine_dates()that automatically discovers the full extent of SleepHQ history by walking backwards in 30-day windows with 90 seconds between batches.run_sleephq_importuses this when no explicit date range is given (the server/trigger path). The existing CLI--days/--from/--topath is unchanged.importer/sleephq_import.py— Passscope="read"tocreate_client()instead of relying on the library default.api/routers/import_settings.py— Removedlookback_daysfrom the trigger path since it no longer applies.frontend/src/pages/Settings.tsx— Removed theLookback daysinput (added in a prior commit) and added a sentence clarifying that only read access is used.Testing
ruff check— cleanpytest— 30 passed, 63 skipped (DB tests require Postgres)tsc --noEmit— no errorsvitest run— 1 passed