doWork
Performs the background data synchronization work.
This method:
Promotes the worker to a foreground service with a progress notification
Calls the repository's sync method which returns a Flow of progress updates
Updates the notification as sync progresses
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))
}Content copied to clipboard
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