Background Sync

Syncing BookNest's Catalog in the Background

The network half of Fetching the Catalog's loadBooks() moved into a new refresh(): Boolean (default true in the interface, so the fakes still compile), which the worker calls; BookNestApp.onCreate() calls SyncScheduler.schedulePeriodic(this).

Can you run the periodic sync now rather than in six hours? JobScheduler can force job 0 of Work Requests:

Forcing WorkManager's job through JobSchedulerShell
adb -s emulator-5556 shell cmd jobscheduler run -f -n androidx.work.systemjobscheduler \
  com.example.booknest 0
Output
Running job [FORCED]
D/WM-WorkerWrapper( 6940): Delaying execution for com.example.booknest.sync.CatalogSyncWorker
because it is being executed before schedule.
D/WM-SystemJobScheduler( 6940): Scheduling work ID f80167f6-25a9-45b4-b8ea-37a5852ce7b8
(com.example.booknest.sync.CatalogSyncWorker), Job ID 8

The worker didn't run: WorkManager 234 checked its own schedule and rescheduled the job (Minimum latency: +5h45m49s). To exercise the worker, enqueue Constraints and Chaining's "sync now", which runs the same class; in tests, work-testing's TestDriver.setPeriodDelayMet(id) ends a period early. And because the catalog observes Room 234 (Offline-First), a background refresh updates a visible list with no extra code.