Skip to content

Instantly share code, notes, and snippets.

@pfmaggi
Last active April 1, 2020 12:40
Show Gist options
  • Save pfmaggi/c702d1fd6c3a8fbbd118c3a901c010e8 to your computer and use it in GitHub Desktop.
Save pfmaggi/c702d1fd6c3a8fbbd118c3a901c010e8 to your computer and use it in GitHub Desktop.
Code for the Medium article: "Customizing WorkManager"
/* 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