Last active
April 1, 2020 12:40
-
-
Save pfmaggi/c702d1fd6c3a8fbbd118c3a901c010e8 to your computer and use it in GitHub Desktop.
Code for the Medium article: "Customizing WorkManager"
This file contains 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
/* Copyright 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 */ | |
class UpvoteStoryWorker( | |
appContext: Context, | |
workerParams: WorkerParameters, | |
private val service: UpvoteStoryHttpApi) | |
: CoroutineWorker(appContext, workerParams) { | |
override suspend fun doWork(): Result { | |
return try { | |
// Upvote story | |
Result.success() | |
} catch (e: Exception) { | |
if (runAttemptCount < MAX_NUMBER_OF_RETRY) { | |
Result.retry() | |
} else { | |
Result.failure() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment