Last active
September 6, 2019 11:10
-
-
Save aggarwalpulkit596/62c630f4d1439db90087b074cd5ec504 to your computer and use it in GitHub Desktop.
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
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