refactor: use a shared timer in JobQueue.kt

This commit is contained in:
jubb 2021-04-06 17:09:21 +10:00
parent 924f58f816
commit 3b2589b835

View File

@ -19,6 +19,7 @@ class JobQueue : JobDelegate {
private val dispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher()
private val scope = GlobalScope + SupervisorJob()
private val queue = Channel<Job>(UNLIMITED)
val timer = Timer()
init {
// process jobs
@ -77,7 +78,7 @@ class JobQueue : JobDelegate {
} else {
val retryInterval = getRetryInterval(job)
Log.i("Jobs", "${job::class.simpleName} failed; scheduling retry (failure count is ${job.failureCount}).")
Timer().schedule(delay = retryInterval) {
timer.schedule(delay = retryInterval) {
Log.i("Jobs", "Retrying ${job::class.simpleName}.")
queue.offer(job)
}