Skip to content

Instantly share code, notes, and snippets.

@aggarwalpulkit596
Last active September 6, 2019 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aggarwalpulkit596/62c630f4d1439db90087b074cd5ec504 to your computer and use it in GitHub Desktop.
Save aggarwalpulkit596/62c630f4d1439db90087b074cd5ec504 to your computer and use it in GitHub Desktop.
class ProgressWorker(context: Context, private val workerParameters: WorkerParameters)
:Worker(context, workerParameters), KoinComponent {
override fun doWork(): Result {
//fecthing the paramaters to make the network call
val contentId = workerParameters.inputData.getString(CONTENT_ID)
val attemptId = workerParameters.inputData.getString(RUN_ATTEMPT_ID)
val progress = Progress()
progress.status = "DONE"
progress.runs = RunAttemptsId(attemptId)
progress.content = ContentsId(contentId)
//Retrofit 2.6.0 with Coroutines
val response = Clients.onlineV2JsonApi.setProgress(progress).execute()
if (response.isSuccessful) {
response.body()?.let {
//Do Some Work like updating the db
}
return Result.success()
} else {
if (response.code() in (500..599)) {
// try again if there is a server error
return Result.retry()
}
return Result.failure()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment