I have a coroutine worker which I would like to be called periodically at ~ 1 minute intervals. How would you go on doing this?
My worker looks like this:
class CloudDataWorker(context: Context, params: WorkerParameters):
CoroutineWorker(context, params) {
companion object {
const val WORK_NAME = "CloudDataWorker"
}
override suspend fun doWork(): Result {
Timber.d("Background worker started.")
val repository = Repository(applicationContext);
return try {
if(repository.getAllJobs().hasActiveObservers()){
Timber.d("Found active listeners on cloud data.")
repository.refreshJobs()
} else {
Timber.d("No active listeners for cloud data found.")
}
Result.success()
} catch (e: HttpException) {
Timber.e("Error during update of cloud data: ${e.message()}")
Result.retry()
}
}
}