Implement background daily update check (Item 4) #4

Merged
fredo merged 1 commit from feature/update-worker into main 2026-09-11 12:58:56 +02:00
Owner

UpdateWorker.doWork() calls repository.refreshCurrentLanguage(), which reuses
the version-gated logic from Item 1:

  • GET /version.json (a few bytes)
  • if version unchanged: update lastCheckedAt only, no download
  • if version newer: download ~1.1 MB, validate (non-empty, ≥80% of current
    count), replace transactionally, persist version + lastCheckedAt

Strategy: check-and-download on any connected network. The full download only
happens when the server version actually changed (typically days/weeks apart),
so the cost on metered connections is acceptable. Keeping data current matters
more for a clinical tool than saving a rare 1.1 MB transfer.

On any failure the existing database is left untouched; Result.failure() is
returned so WorkManager reschedules for the next daily window without aggressive
retries. The staleness indicator in the UI alerts the user on next open.

Scheduled from MainActivity.onCreate() with ExistingPeriodicWorkPolicy.KEEP so
repeated launches do not reset the 24-hour timer. Constraints: network connected,
battery not low. Flex window: 3 hours within each 24-hour period.

Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com

UpdateWorker.doWork() calls repository.refreshCurrentLanguage(), which reuses the version-gated logic from Item 1: - GET /version.json (a few bytes) - if version unchanged: update lastCheckedAt only, no download - if version newer: download ~1.1 MB, validate (non-empty, ≥80% of current count), replace transactionally, persist version + lastCheckedAt Strategy: check-and-download on any connected network. The full download only happens when the server version actually changed (typically days/weeks apart), so the cost on metered connections is acceptable. Keeping data current matters more for a clinical tool than saving a rare 1.1 MB transfer. On any failure the existing database is left untouched; Result.failure() is returned so WorkManager reschedules for the next daily window without aggressive retries. The staleness indicator in the UI alerts the user on next open. Scheduled from MainActivity.onCreate() with ExistingPeriodicWorkPolicy.KEEP so repeated launches do not reset the 24-hour timer. Constraints: network connected, battery not low. Flex window: 3 hours within each 24-hour period. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
UpdateWorker.doWork() calls repository.refreshCurrentLanguage(), which reuses
the version-gated logic from Item 1:
  - GET /version.json (a few bytes)
  - if version unchanged: update lastCheckedAt only, no download
  - if version newer: download ~1.1 MB, validate (non-empty, ≥80% of current
    count), replace transactionally, persist version + lastCheckedAt

Strategy: check-and-download on any connected network. The full download only
happens when the server version actually changed (typically days/weeks apart),
so the cost on metered connections is acceptable. Keeping data current matters
more for a clinical tool than saving a rare 1.1 MB transfer.

On any failure the existing database is left untouched; Result.failure() is
returned so WorkManager reschedules for the next daily window without aggressive
retries. The staleness indicator in the UI alerts the user on next open.

Scheduled from MainActivity.onCreate() with ExistingPeriodicWorkPolicy.KEEP so
repeated launches do not reset the 24-hour timer. Constraints: network connected,
battery not low. Flex window: 3 hours within each 24-hour period.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
fredo merged commit 2d1f7af744 into main 2026-09-11 12:58:56 +02:00
fredo deleted branch feature/update-worker 2026-09-12 18:49:42 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
fredo/Compendium!4
No description provided.