refactor: use a shared timer in JobQueue.kt

pull/486/head
jubb 3 years ago
parent 924f58f816
commit 3b2589b835

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

Loading…
Cancel
Save