diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/BackgroundWorkHelper.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/BackgroundWorkHelper.kt index c7e797fa3a075a6cfb7cded9f63f8058533aa00c..9e9fb0a702ba1f8268bd0e1c231776fccb7f55fe 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/BackgroundWorkHelper.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/BackgroundWorkHelper.kt @@ -5,6 +5,7 @@ import androidx.work.Constraints import androidx.work.NetworkType import de.rki.coronawarnapp.notification.NotificationHelper import de.rki.coronawarnapp.storage.LocalData +import timber.log.Timber import kotlin.random.Random /** @@ -90,6 +91,7 @@ object BackgroundWorkHelper { * @see LocalData.backgroundNotification() */ fun sendDebugNotification(title: String, content: String) { + Timber.d("sendDebugNotification(title=%s, content=%s)", title, content) if (!LocalData.backgroundNotification()) return NotificationHelper.sendNotification(title, content, NotificationCompat.PRIORITY_HIGH, true) } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/DiagnosisKeyRetrievalOneTimeWorker.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/DiagnosisKeyRetrievalOneTimeWorker.kt index e45eb28baae14e26ea910330763c46ccf2a766b1..c404b59e4dc9ad722c6d87f9e50fc51a453c48b0 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/DiagnosisKeyRetrievalOneTimeWorker.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/DiagnosisKeyRetrievalOneTimeWorker.kt @@ -27,28 +27,40 @@ class DiagnosisKeyRetrievalOneTimeWorker(val context: Context, workerParams: Wor * @see RetrieveDiagnosisKeysTransaction */ override suspend fun doWork(): Result { - Timber.d("Background job started. Run attempt: $runAttemptCount ") + Timber.tag(TAG).d("$id: doWork() started. Run attempt: $runAttemptCount") + BackgroundWorkHelper.sendDebugNotification( - "KeyOneTime Executing: Start", "KeyOneTime started. Run attempt: $runAttemptCount ") + "KeyOneTime Executing: Start", "KeyOneTime started. Run attempt: $runAttemptCount " + ) var result = Result.success() try { RetrieveDiagnosisKeysTransaction.startWithConstraints() } catch (e: Exception) { + Timber.tag(TAG).w( + e, "$id: Error during RetrieveDiagnosisKeysTransaction.startWithConstraints()." + ) + if (runAttemptCount > BackgroundConstants.WORKER_RETRY_COUNT_THRESHOLD) { + Timber.tag(TAG).w(e, "$id: Retry attempts exceeded.") BackgroundWorkHelper.sendDebugNotification( - "KeyOneTime Executing: Failure", "KeyOneTime failed with $runAttemptCount attempts") + "KeyOneTime Executing: Failure", + "KeyOneTime failed with $runAttemptCount attempts" + ) return Result.failure() } else { + Timber.tag(TAG).d(e, "$id: Retrying.") result = Result.retry() } } BackgroundWorkHelper.sendDebugNotification( - "KeyOneTime Executing: End", "KeyOneTime result: $result ") + "KeyOneTime Executing: End", "KeyOneTime result: $result " + ) + Timber.tag(TAG).d("$id: doWork() finished with %s", result) return result } } diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/DiagnosisKeyRetrievalPeriodicWorker.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/DiagnosisKeyRetrievalPeriodicWorker.kt index 79f091610676c9184dfef85882a5dfa83e972eb2..03417c1999a69c6477206a408485c837ab503f7f 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/DiagnosisKeyRetrievalPeriodicWorker.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/worker/DiagnosisKeyRetrievalPeriodicWorker.kt @@ -28,28 +28,40 @@ class DiagnosisKeyRetrievalPeriodicWorker(val context: Context, workerParams: Wo * @see BackgroundWorkScheduler.scheduleDiagnosisKeyOneTimeWork() */ override suspend fun doWork(): Result { - Timber.d("Background job started. Run attempt: $runAttemptCount") + Timber.tag(TAG).d("$id: doWork() started. Run attempt: $runAttemptCount") + BackgroundWorkHelper.sendDebugNotification( - "KeyPeriodic Executing: Start", "KeyPeriodic started. Run attempt: $runAttemptCount ") + "KeyPeriodic Executing: Start", "KeyPeriodic started. Run attempt: $runAttemptCount" + ) var result = Result.success() try { BackgroundWorkScheduler.scheduleDiagnosisKeyOneTimeWork() } catch (e: Exception) { + Timber.tag(TAG).w( + e, "$id: Error during BackgroundWorkScheduler.scheduleDiagnosisKeyOneTimeWork()." + ) + if (runAttemptCount > BackgroundConstants.WORKER_RETRY_COUNT_THRESHOLD) { + Timber.tag(TAG).w(e, "$id: Retry attempts exceeded.") BackgroundWorkHelper.sendDebugNotification( - "KeyPeriodic Executing: Failure", "KeyPeriodic failed with $runAttemptCount attempts") + "KeyPeriodic Executing: Failure", + "KeyPeriodic failed with $runAttemptCount attempts" + ) return Result.failure() } else { + Timber.tag(TAG).d(e, "$id: Retrying.") result = Result.retry() } } BackgroundWorkHelper.sendDebugNotification( - "KeyPeriodic Executing: End", "KeyPeriodic result: $result ") + "KeyPeriodic Executing: End", "KeyPeriodic result: $result " + ) + Timber.tag(TAG).d("$id: doWork() finished with %s", result) return result } }