Skip to content
Snippets Groups Projects
Unverified Commit ec88c722 authored by Matthias Urhahn's avatar Matthias Urhahn Committed by GitHub
Browse files

Make worker type visible on log output (DEV) #1714

parent 9bca0648
No related branches found
No related tags found
No related merge requests found
Showing
with 64 additions and 61 deletions
...@@ -22,10 +22,10 @@ class DeadmanNotificationOneTimeWorker @AssistedInject constructor( ...@@ -22,10 +22,10 @@ class DeadmanNotificationOneTimeWorker @AssistedInject constructor(
CoroutineWorker(context, workerParams) { CoroutineWorker(context, workerParams) {
override suspend fun doWork(): Result { override suspend fun doWork(): Result {
Timber.d("Background job started. Run attempt: $runAttemptCount") Timber.tag(TAG).d("Background job started. Run attempt: $runAttemptCount")
if (runAttemptCount > BackgroundConstants.WORKER_RETRY_COUNT_THRESHOLD) { if (runAttemptCount > BackgroundConstants.WORKER_RETRY_COUNT_THRESHOLD) {
Timber.d("Background job failed after $runAttemptCount attempts. Rescheduling") Timber.tag(TAG).d("Background job failed after $runAttemptCount attempts. Rescheduling")
return Result.failure() return Result.failure()
} }
...@@ -41,4 +41,8 @@ class DeadmanNotificationOneTimeWorker @AssistedInject constructor( ...@@ -41,4 +41,8 @@ class DeadmanNotificationOneTimeWorker @AssistedInject constructor(
@AssistedInject.Factory @AssistedInject.Factory
interface Factory : InjectedWorkerFactory<DeadmanNotificationOneTimeWorker> interface Factory : InjectedWorkerFactory<DeadmanNotificationOneTimeWorker>
companion object {
private val TAG = DeadmanNotificationOneTimeWorker::class.java.simpleName
}
} }
...@@ -22,10 +22,10 @@ class DeadmanNotificationPeriodicWorker @AssistedInject constructor( ...@@ -22,10 +22,10 @@ class DeadmanNotificationPeriodicWorker @AssistedInject constructor(
CoroutineWorker(context, workerParams) { CoroutineWorker(context, workerParams) {
override suspend fun doWork(): Result { override suspend fun doWork(): Result {
Timber.d("Background job started. Run attempt: $runAttemptCount") Timber.tag(TAG).d("Background job started. Run attempt: $runAttemptCount")
if (runAttemptCount > BackgroundConstants.WORKER_RETRY_COUNT_THRESHOLD) { if (runAttemptCount > BackgroundConstants.WORKER_RETRY_COUNT_THRESHOLD) {
Timber.d("Background job failed after $runAttemptCount attempts. Rescheduling") Timber.tag(TAG).d("Background job failed after $runAttemptCount attempts. Rescheduling")
return Result.failure() return Result.failure()
} }
...@@ -34,7 +34,7 @@ class DeadmanNotificationPeriodicWorker @AssistedInject constructor( ...@@ -34,7 +34,7 @@ class DeadmanNotificationPeriodicWorker @AssistedInject constructor(
// Schedule one time deadman notification send work // Schedule one time deadman notification send work
scheduler.scheduleOneTime() scheduler.scheduleOneTime()
} catch (e: Exception) { } catch (e: Exception) {
Timber.d(e) Timber.tag(TAG).d(e)
result = Result.retry() result = Result.retry()
} }
...@@ -43,4 +43,8 @@ class DeadmanNotificationPeriodicWorker @AssistedInject constructor( ...@@ -43,4 +43,8 @@ class DeadmanNotificationPeriodicWorker @AssistedInject constructor(
@AssistedInject.Factory @AssistedInject.Factory
interface Factory : InjectedWorkerFactory<DeadmanNotificationPeriodicWorker> interface Factory : InjectedWorkerFactory<DeadmanNotificationPeriodicWorker>
companion object {
private val TAG = DeadmanNotificationPeriodicWorker::class.java.simpleName
}
} }
...@@ -22,12 +22,10 @@ class ExposureStateUpdateWorker @AssistedInject constructor( ...@@ -22,12 +22,10 @@ class ExposureStateUpdateWorker @AssistedInject constructor(
override suspend fun doWork(): Result { override suspend fun doWork(): Result {
try { try {
Timber.v("worker to persist exposure summary started")
taskController.submit( taskController.submit(
DefaultTaskRequest(RiskLevelTask::class, originTag = "ExposureStateUpdateWorker") DefaultTaskRequest(RiskLevelTask::class, originTag = "ExposureStateUpdateWorker")
) )
Timber.v("risk level calculation triggered") Timber.tag(TAG).v("Risk level calculation triggered")
} catch (e: ApiException) { } catch (e: ApiException) {
e.report(ExceptionCategory.EXPOSURENOTIFICATION) e.report(ExceptionCategory.EXPOSURENOTIFICATION)
} }
...@@ -37,4 +35,8 @@ class ExposureStateUpdateWorker @AssistedInject constructor( ...@@ -37,4 +35,8 @@ class ExposureStateUpdateWorker @AssistedInject constructor(
@AssistedInject.Factory @AssistedInject.Factory
interface Factory : InjectedWorkerFactory<ExposureStateUpdateWorker> interface Factory : InjectedWorkerFactory<ExposureStateUpdateWorker>
companion object {
private val TAG = ExposureStateUpdateWorker::class.java.simpleName
}
} }
...@@ -20,13 +20,8 @@ class BackgroundNoiseOneTimeWorker @AssistedInject constructor( ...@@ -20,13 +20,8 @@ class BackgroundNoiseOneTimeWorker @AssistedInject constructor(
private val playbook: Playbook private val playbook: Playbook
) : CoroutineWorker(context, workerParams) { ) : CoroutineWorker(context, workerParams) {
/**
* Work execution
*
* @return Result
*/
override suspend fun doWork(): Result { override suspend fun doWork(): Result {
Timber.d("$id: doWork() started. Run attempt: $runAttemptCount") Timber.tag(TAG).d("$id: doWork() started. Run attempt: $runAttemptCount")
var result = Result.success() var result = Result.success()
try { try {
...@@ -40,10 +35,14 @@ class BackgroundNoiseOneTimeWorker @AssistedInject constructor( ...@@ -40,10 +35,14 @@ class BackgroundNoiseOneTimeWorker @AssistedInject constructor(
} }
} }
Timber.d("$id: doWork() finished with %s", result) Timber.tag(TAG).d("$id: doWork() finished with %s", result)
return result return result
} }
@AssistedInject.Factory @AssistedInject.Factory
interface Factory : InjectedWorkerFactory<BackgroundNoiseOneTimeWorker> interface Factory : InjectedWorkerFactory<BackgroundNoiseOneTimeWorker>
companion object {
private val TAG = BackgroundNoiseOneTimeWorker::class.java.simpleName
}
} }
...@@ -22,19 +22,11 @@ class BackgroundNoisePeriodicWorker @AssistedInject constructor( ...@@ -22,19 +22,11 @@ class BackgroundNoisePeriodicWorker @AssistedInject constructor(
@Assisted workerParams: WorkerParameters @Assisted workerParams: WorkerParameters
) : CoroutineWorker(context, workerParams) { ) : CoroutineWorker(context, workerParams) {
companion object {
private val TAG: String? = BackgroundNoisePeriodicWorker::class.simpleName
}
/** /**
* Work execution
*
* @return Result
*
* @see BackgroundConstants.NUMBER_OF_DAYS_TO_RUN_PLAYBOOK * @see BackgroundConstants.NUMBER_OF_DAYS_TO_RUN_PLAYBOOK
*/ */
override suspend fun doWork(): Result { override suspend fun doWork(): Result {
Timber.d("$id: doWork() started. Run attempt: $runAttemptCount") Timber.tag(TAG).d("$id: doWork() started. Run attempt: $runAttemptCount")
var result = Result.success() var result = Result.success()
try { try {
...@@ -57,15 +49,19 @@ class BackgroundNoisePeriodicWorker @AssistedInject constructor( ...@@ -57,15 +49,19 @@ class BackgroundNoisePeriodicWorker @AssistedInject constructor(
Result.retry() Result.retry()
} }
} }
Timber.d("$id: doWork() finished with %s", result) Timber.tag(TAG).d("$id: doWork() finished with %s", result)
return result return result
} }
private fun stopWorker() { private fun stopWorker() {
BackgroundWorkScheduler.WorkType.BACKGROUND_NOISE_PERIODIC_WORK.stop() BackgroundWorkScheduler.WorkType.BACKGROUND_NOISE_PERIODIC_WORK.stop()
Timber.d("$id: worker stopped") Timber.tag(TAG).d("$id: worker stopped")
} }
@AssistedInject.Factory @AssistedInject.Factory
interface Factory : InjectedWorkerFactory<BackgroundNoisePeriodicWorker> interface Factory : InjectedWorkerFactory<BackgroundNoisePeriodicWorker>
companion object {
private val TAG = BackgroundNoisePeriodicWorker::class.java.simpleName
}
} }
...@@ -24,13 +24,8 @@ class DiagnosisKeyRetrievalOneTimeWorker @AssistedInject constructor( ...@@ -24,13 +24,8 @@ class DiagnosisKeyRetrievalOneTimeWorker @AssistedInject constructor(
private val taskController: TaskController private val taskController: TaskController
) : CoroutineWorker(context, workerParams) { ) : CoroutineWorker(context, workerParams) {
/**
* Work execution
*
* @return Result
*/
override suspend fun doWork(): Result { override suspend fun doWork(): Result {
Timber.d("$id: doWork() started. Run attempt: $runAttemptCount") Timber.tag(TAG).d("$id: doWork() started. Run attempt: $runAttemptCount")
var result = Result.success() var result = Result.success()
taskController.submitBlocking( taskController.submitBlocking(
...@@ -40,22 +35,26 @@ class DiagnosisKeyRetrievalOneTimeWorker @AssistedInject constructor( ...@@ -40,22 +35,26 @@ class DiagnosisKeyRetrievalOneTimeWorker @AssistedInject constructor(
originTag = "DiagnosisKeyRetrievalOneTimeWorker" originTag = "DiagnosisKeyRetrievalOneTimeWorker"
) )
).error?.also { error: Throwable -> ).error?.also { error: Throwable ->
Timber.w(error, "$id: Error when submitting DownloadDiagnosisKeysTask.") Timber.tag(TAG).w(error, "$id: Error when submitting DownloadDiagnosisKeysTask.")
if (runAttemptCount > BackgroundConstants.WORKER_RETRY_COUNT_THRESHOLD) { if (runAttemptCount > BackgroundConstants.WORKER_RETRY_COUNT_THRESHOLD) {
Timber.w(error, "$id: Retry attempts exceeded.") Timber.tag(TAG).w(error, "$id: Retry attempts exceeded.")
return Result.failure() return Result.failure()
} else { } else {
Timber.d(error, "$id: Retrying.") Timber.tag(TAG).d(error, "$id: Retrying.")
result = Result.retry() result = Result.retry()
} }
} }
Timber.d("$id: doWork() finished with %s", result) Timber.tag(TAG).d("$id: doWork() finished with %s", result)
return result return result
} }
@AssistedInject.Factory @AssistedInject.Factory
interface Factory : InjectedWorkerFactory<DiagnosisKeyRetrievalOneTimeWorker> interface Factory : InjectedWorkerFactory<DiagnosisKeyRetrievalOneTimeWorker>
companion object {
private val TAG = DiagnosisKeyRetrievalOneTimeWorker::class.java.simpleName
}
} }
...@@ -21,38 +21,38 @@ class DiagnosisKeyRetrievalPeriodicWorker @AssistedInject constructor( ...@@ -21,38 +21,38 @@ class DiagnosisKeyRetrievalPeriodicWorker @AssistedInject constructor(
) : CoroutineWorker(context, workerParams) { ) : CoroutineWorker(context, workerParams) {
/** /**
* Work execution
*
* @return Result
*
* @see BackgroundWorkScheduler.scheduleDiagnosisKeyPeriodicWork() * @see BackgroundWorkScheduler.scheduleDiagnosisKeyPeriodicWork()
* @see BackgroundWorkScheduler.scheduleDiagnosisKeyOneTimeWork() * @see BackgroundWorkScheduler.scheduleDiagnosisKeyOneTimeWork()
*/ */
override suspend fun doWork(): Result { override suspend fun doWork(): Result {
Timber.d("$id: doWork() started. Run attempt: $runAttemptCount") Timber.tag(TAG).d("$id: doWork() started. Run attempt: $runAttemptCount")
var result = Result.success() var result = Result.success()
try { try {
BackgroundWorkScheduler.scheduleDiagnosisKeyOneTimeWork() BackgroundWorkScheduler.scheduleDiagnosisKeyOneTimeWork()
} catch (e: Exception) { } catch (e: Exception) {
Timber.w( Timber.tag(TAG).w(
e, "$id: Error during BackgroundWorkScheduler.scheduleDiagnosisKeyOneTimeWork()." e, "$id: Error during BackgroundWorkScheduler.scheduleDiagnosisKeyOneTimeWork()."
) )
if (runAttemptCount > BackgroundConstants.WORKER_RETRY_COUNT_THRESHOLD) { if (runAttemptCount > BackgroundConstants.WORKER_RETRY_COUNT_THRESHOLD) {
Timber.w(e, "$id: Retry attempts exceeded.") Timber.tag(TAG).w(e, "$id: Retry attempts exceeded.")
return Result.failure() return Result.failure()
} else { } else {
Timber.d(e, "$id: Retrying.") Timber.tag(TAG).d(e, "$id: Retrying.")
result = Result.retry() result = Result.retry()
} }
} }
Timber.d("$id: doWork() finished with %s", result) Timber.tag(TAG).d("$id: doWork() finished with %s", result)
return result return result
} }
@AssistedInject.Factory @AssistedInject.Factory
interface Factory : InjectedWorkerFactory<DiagnosisKeyRetrievalPeriodicWorker> interface Factory : InjectedWorkerFactory<DiagnosisKeyRetrievalPeriodicWorker>
companion object {
private val TAG = DiagnosisKeyRetrievalPeriodicWorker::class.java.simpleName
}
} }
...@@ -27,25 +27,20 @@ class DiagnosisTestResultRetrievalPeriodicWorker @AssistedInject constructor( ...@@ -27,25 +27,20 @@ class DiagnosisTestResultRetrievalPeriodicWorker @AssistedInject constructor(
) : CoroutineWorker(context, workerParams) { ) : CoroutineWorker(context, workerParams) {
/** /**
* Work execution
*
* If background job is running for less than 21 days, testResult is checked. * If background job is running for less than 21 days, testResult is checked.
* If the job is running for more than 21 days, the job will be stopped * If the job is running for more than 21 days, the job will be stopped
* *
* @return Result
*
* @see LocalData.isTestResultNotificationSent * @see LocalData.isTestResultNotificationSent
* @see LocalData.initialPollingForTestResultTimeStamp * @see LocalData.initialPollingForTestResultTimeStamp
*/ */
override suspend fun doWork(): Result { override suspend fun doWork(): Result {
Timber.tag(TAG).d("$id: doWork() started. Run attempt: $runAttemptCount")
Timber.d("$id: doWork() started. Run attempt: $runAttemptCount")
if (runAttemptCount > BackgroundConstants.WORKER_RETRY_COUNT_THRESHOLD) { if (runAttemptCount > BackgroundConstants.WORKER_RETRY_COUNT_THRESHOLD) {
Timber.d("$id doWork() failed after $runAttemptCount attempts. Rescheduling") Timber.tag(TAG).d("$id doWork() failed after $runAttemptCount attempts. Rescheduling")
BackgroundWorkScheduler.scheduleDiagnosisKeyPeriodicWork() BackgroundWorkScheduler.scheduleDiagnosisKeyPeriodicWork()
Timber.d("$id Rescheduled background worker") Timber.tag(TAG).d("$id Rescheduled background worker")
return Result.failure() return Result.failure()
} }
...@@ -56,19 +51,19 @@ class DiagnosisTestResultRetrievalPeriodicWorker @AssistedInject constructor( ...@@ -56,19 +51,19 @@ class DiagnosisTestResultRetrievalPeriodicWorker @AssistedInject constructor(
System.currentTimeMillis() System.currentTimeMillis()
) < BackgroundConstants.POLLING_VALIDITY_MAX_DAYS ) < BackgroundConstants.POLLING_VALIDITY_MAX_DAYS
) { ) {
Timber.d(" $id maximum days not exceeded") Timber.tag(TAG).d(" $id maximum days not exceeded")
val testResult = SubmissionService.asyncRequestTestResult() val testResult = SubmissionService.asyncRequestTestResult()
initiateNotification(testResult) initiateNotification(testResult)
Timber.d(" $id Test Result Notification Initiated") Timber.tag(TAG).d(" $id Test Result Notification Initiated")
} else { } else {
stopWorker() stopWorker()
Timber.d(" $id worker stopped") Timber.tag(TAG).d(" $id worker stopped")
} }
} catch (e: Exception) { } catch (e: Exception) {
result = Result.retry() result = Result.retry()
} }
Timber.d("$id: doWork() finished with %s", result) Timber.tag(TAG).d("$id: doWork() finished with %s", result)
return result return result
} }
...@@ -86,10 +81,10 @@ class DiagnosisTestResultRetrievalPeriodicWorker @AssistedInject constructor( ...@@ -86,10 +81,10 @@ class DiagnosisTestResultRetrievalPeriodicWorker @AssistedInject constructor(
*/ */
private fun initiateNotification(testResult: TestResult) { private fun initiateNotification(testResult: TestResult) {
if (LocalData.isTestResultNotificationSent() || LocalData.submissionWasSuccessful()) { if (LocalData.isTestResultNotificationSent() || LocalData.submissionWasSuccessful()) {
Timber.d("$id: Notification already sent or there was a successful submission") Timber.tag(TAG).d("$id: Notification already sent or there was a successful submission")
return return
} }
Timber.d("$id: Test Result retried is $testResult") Timber.tag(TAG).d("$id: Test Result retried is $testResult")
if (testResult == TestResult.NEGATIVE || testResult == TestResult.POSITIVE || if (testResult == TestResult.NEGATIVE || testResult == TestResult.POSITIVE ||
testResult == TestResult.INVALID testResult == TestResult.INVALID
) { ) {
...@@ -100,7 +95,7 @@ class DiagnosisTestResultRetrievalPeriodicWorker @AssistedInject constructor( ...@@ -100,7 +95,7 @@ class DiagnosisTestResultRetrievalPeriodicWorker @AssistedInject constructor(
CoronaWarnApplication.getAppContext() CoronaWarnApplication.getAppContext()
.getString(R.string.notification_body) .getString(R.string.notification_body)
) )
Timber.d("$id: Test Result available and notification is initiated") Timber.tag(TAG).d("$id: Test Result available and notification is initiated")
} }
LocalData.isTestResultNotificationSent(true) LocalData.isTestResultNotificationSent(true)
stopWorker() stopWorker()
...@@ -116,9 +111,13 @@ class DiagnosisTestResultRetrievalPeriodicWorker @AssistedInject constructor( ...@@ -116,9 +111,13 @@ class DiagnosisTestResultRetrievalPeriodicWorker @AssistedInject constructor(
private fun stopWorker() { private fun stopWorker() {
LocalData.initialPollingForTestResultTimeStamp(0L) LocalData.initialPollingForTestResultTimeStamp(0L)
BackgroundWorkScheduler.WorkType.DIAGNOSIS_TEST_RESULT_PERIODIC_WORKER.stop() BackgroundWorkScheduler.WorkType.DIAGNOSIS_TEST_RESULT_PERIODIC_WORKER.stop()
Timber.d("$id: Background worker stopped") Timber.tag(TAG).d("$id: Background worker stopped")
} }
@AssistedInject.Factory @AssistedInject.Factory
interface Factory : InjectedWorkerFactory<DiagnosisTestResultRetrievalPeriodicWorker> interface Factory : InjectedWorkerFactory<DiagnosisTestResultRetrievalPeriodicWorker>
companion object {
private val TAG = DiagnosisTestResultRetrievalPeriodicWorker::class.java.simpleName
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment