doWork

open suspend override fun doWork(): ListenableWorker.Result

Performs the background data synchronization work.

This method:

  1. Promotes the worker to a foreground service with a progress notification

  2. Calls the repository's sync method which returns a Flow of progress updates

  3. Updates the notification as sync progresses

  4. Returns success/retry/failure based on the outcome

Sync Flow

homeRepository.sync() // Returns Flow<SyncProgress>
.collect { progress ->
// Update notification with current progress
setForeground(getForegroundInfo(progress.total, progress.current))
}

Error Handling

  • Retry: If runAttemptCount<TOTAL_SYNC_ATTEMPTS, returns Result.retry()

  • Failure: After exhausting retries, returns Result.failure()

  • Success: Returns Result.success() when sync completes without errors

Threading

All operations run on ioDispatcher to avoid blocking the main thread.

Return

Result.success if sync completed successfully, Result.retry if sync failed but retries remain, Result.failure if sync failed after all retries