Skip to content

Instantly share code, notes, and snippets.

@enginebai
Created December 21, 2018 12:33
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 enginebai/118b79f90809804d1e8383b48420af0a to your computer and use it in GitHub Desktop.
Save enginebai/118b79f90809804d1e8383b48420af0a to your computer and use it in GitHub Desktop.
class FileUploadWorker(context: Context, params: WorkerParameters) : Woker(context, params) {
override fun doWork(): Result {
return try {
val response = ... // send PUT /message/media reequest
when (uploadResponse.code() / 100) {
2 -> Result.SUCCESS
4 -> Result.FAILURE
else -> Result.RETRY
}
} catch (e: FileNotFoundException) {
Result.FAILURE
} catch (e: IOException) {
Result.RETRY
} finally {
... // close resources
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment