I have a periodic work request that is suddenly stopping its recurrences after a day or more.
inline fun <reified W : Worker> Context.schedule(repeatInterval: Long = 1,
interval: TimeUnit = TimeUnit.HOURS,
flexTimeInterval: Long? = null,
flexInterval: TimeUnit? = null,
constraints: Constraints = networkConstraint) {
val workManager = WorkManager.getInstance(this)
val workRequestBuilder = if (flexInterval != null && flexTimeInterval != null) {
PeriodicWorkRequestBuilder<W>(repeatInterval, interval, flexTimeInterval, flexInterval)
} else {
PeriodicWorkRequestBuilder<W>(repeatInterval, interval)
}
val work = workRequestBuilder
.setConstraints(constraints)
.addTag(W::class.java.name)
.build()
background {
workManager.cancelAllWorkByTag(W::class.java.name).await()
workManager.enqueue(work)
}
}
It has been fine up until the latest version of my application. Where I've noticed it just stops recurring after a while. Previously it went on for months on end no problems.
My question is what are the reasons other than the periodic work request being cancelled for it to suddenly stop? If a job were to hang and block it's thread and never return the Work result would this cause issues? According to the documentation if the job does not return in 10 minutes it is stopped. That is why I am so confused... the only place I cancel it is right before I schedule it.
It is scheduled every 35 minutes:
fun schedule(context: Context) = context.schedule<DeviceCheckInWorker>(
flexTimeInterval = 15,
interval = TimeUnit.MINUTES,
repeatInterval = 35,
flexInterval = TimeUnit.MINUTES)