Make workers non-cancellable

pull/1061/head
Alex Baker 4 years ago
parent 640412314c
commit fca4a721da

@ -1,20 +1,24 @@
package org.tasks.injection
import android.content.Context
import androidx.work.CoroutineWorker
import androidx.work.Worker
import androidx.work.WorkerParameters
import kotlinx.coroutines.runBlocking
import org.tasks.analytics.Firebase
import timber.log.Timber
abstract class BaseWorker(
internal val context: Context,
workerParams: WorkerParameters,
internal val firebase: Firebase) : CoroutineWorker(context, workerParams) {
internal val firebase: Firebase
) : Worker(context, workerParams) {
override suspend fun doWork(): Result {
override fun doWork(): Result {
Timber.d("%s.doWork()", javaClass.simpleName)
return try {
run()
runBlocking {
run()
}
} catch (e: Exception) {
firebase.reportException(e)
Result.failure()

@ -2,17 +2,21 @@ package org.tasks.jobs
import android.content.Context
import androidx.work.WorkerParameters
import kotlinx.coroutines.runBlocking
import org.tasks.analytics.Firebase
import org.tasks.injection.BaseWorker
abstract class RepeatingWorker internal constructor(
context: Context,
workerParams: WorkerParameters,
firebase: Firebase) : BaseWorker(context, workerParams, firebase) {
firebase: Firebase
) : BaseWorker(context, workerParams, firebase) {
override suspend fun doWork(): Result {
override fun doWork(): Result {
val result = super.doWork()
scheduleNext()
runBlocking {
scheduleNext()
}
return result
}

@ -210,7 +210,7 @@ class WorkManagerImpl constructor(
.build()
@SuppressLint("EnqueueWork")
private suspend fun enqueueUnique(key: String, c: Class<out CoroutineWorker?>, time: Long) {
private suspend fun enqueueUnique(key: String, c: Class<out Worker?>, time: Long) {
val delay = time - DateUtilities.now()
val builder = OneTimeWorkRequest.Builder(c)
if (delay > 0) {

Loading…
Cancel
Save