Reputation: 171
This is my first question in StackOverflow, so please excuse me for any common mistake I could make. I´m using a CoroutineWorker in Android to make a mutation in GraphQL, the idea is mainly to receive thru a push notification a Token and then, with this Worker send a mutation to the server.
I've managed to do it just fine, but I´m analyzing how this worker behaves when I add a BackOff Strategy to it. Let´s say that this worker sends this first mutation, and for some reason, the server is down... so no problem, with the backOff strategy it will keep sending and retrying. But the question is, for how long keeps retrying without achieving the Result. success() logic? Is there is a limit to it?
I couldn't find any info in the official doc:
Retry and Backoff
This is how my worker looks like:
class Worker @AssistedInject constructor(
@Assisted params: WorkerParameters,
appContext: Context,
private val repo: Repo
) : CoroutineWorker(appContext, params) {
override suspend fun doWork(): Result = withContext(Dispatchers.IO) {
try {
repo.sendMutation().data?.let{ r ->
if(r.result == "OK") {
Result.Succes()
}
}
Result.Retry()
} catch (e: Exception) {
Result.retry()
}
}
}
And this is the backoff strategy I configured:
worker.enqueue(
OneTimeWorkRequestBuilder<Worker>()
.setBackoffCriteria(
BackoffPolicy.EXPONENTIAL,
OneTimeWorkRequest.MIN_BACKOFF_MILLIS,
TimeUnit.MILLISECONDS)
.setConstraints(
Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build()
).build()
)
I would appreciate any help I could get.
Upvotes: 1
Views: 1712
Reputation: 171
So, at the end I was able to find this post in IssueTracker: https://issuetracker.google.com/issues/115708468?pli=1.
It turns out that it never ends to retries until it reaches the Result.success()
.
Upvotes: 1