mirror of https://github.com/tasks/tasks
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
751 B
Kotlin
29 lines
751 B
Kotlin
package org.tasks.injection
|
|
|
|
import android.content.Context
|
|
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
|
|
) : Worker(context, workerParams) {
|
|
|
|
override fun doWork(): Result {
|
|
Timber.d("%s.doWork()", javaClass.simpleName)
|
|
return try {
|
|
runBlocking {
|
|
run()
|
|
}
|
|
} catch (e: Exception) {
|
|
firebase.reportException(e)
|
|
Result.failure()
|
|
}
|
|
}
|
|
|
|
protected abstract suspend fun run(): Result
|
|
} |