Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SendData Worker example
class SendDataWorker(context: Context, params: WorkerParameters) : Worker(context, params), KoinComponent {
@SuppressLint("CheckResult")
override fun doWork(): Result {
val sendService: SendService? by inject()
val data = inputData.getString("data")
val dataInput = getGsonForJoda()?.fromJson(data, SomeDataClass::class.java)
return try {
val query = sendService?.sendData(dataInput)
?.blockingGet()
if (query == null) {
Result.success()
} else {
Result.retry()
}
} catch (e: IOException) {
Result.retry()
} catch (e: Exception) {
if (e.cause is IOException) {
Result.retry()
} else {
Result.failure()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.