refactor: move logs to timber
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package com.bitcointxoko.gudariwallet.sync
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import timber.log.Timber
|
||||
import androidx.work.CoroutineWorker
|
||||
import androidx.work.WorkerParameters
|
||||
import androidx.work.workDataOf
|
||||
@@ -29,11 +29,11 @@ class HistoricalSyncWorker(
|
||||
override suspend fun doWork(): Result {
|
||||
// Guard: already completed — safe if WorkManager ever retries a success
|
||||
if (syncStore.isComplete()) {
|
||||
Log.d(TAG, "Already complete — skipping")
|
||||
Timber.d("Already complete — skipping")
|
||||
return Result.success()
|
||||
}
|
||||
|
||||
Log.d(TAG, "Starting historical payment sync")
|
||||
Timber.d("Starting historical payment sync")
|
||||
var offset = 0
|
||||
var total = -1
|
||||
|
||||
@@ -41,14 +41,14 @@ class HistoricalSyncWorker(
|
||||
val page = runCatching {
|
||||
repo.getPaymentsPaginated(offset = offset, limit = PAGE_SIZE)
|
||||
}.getOrElse { e ->
|
||||
Log.w(TAG, "Network error on offset=$offset: ${e.message} — scheduling retry")
|
||||
Timber.w("Network error on offset=$offset: ${e.message} — scheduling retry")
|
||||
return Result.retry() // WorkManager applies exponential backoff automatically
|
||||
}
|
||||
|
||||
// First page: learn the real total from the server
|
||||
if (total == -1) {
|
||||
total = page.total
|
||||
Log.d(TAG, "Server reports $total total payments")
|
||||
Timber.d("Server reports $total total payments")
|
||||
if (total == 0) {
|
||||
syncStore.markComplete()
|
||||
return Result.success()
|
||||
@@ -59,7 +59,7 @@ class HistoricalSyncWorker(
|
||||
paymentCache.mergePayments(page.data)
|
||||
offset += page.data.size
|
||||
|
||||
Log.d(TAG, "Progress: $offset / $total")
|
||||
Timber.d("Progress: $offset / $total")
|
||||
setProgress(workDataOf(
|
||||
KEY_FETCHED to offset,
|
||||
KEY_TOTAL to total
|
||||
@@ -70,7 +70,7 @@ class HistoricalSyncWorker(
|
||||
}
|
||||
|
||||
syncStore.markComplete()
|
||||
Log.d(TAG, "Historical sync complete — $offset payments stored")
|
||||
Timber.d("Historical sync complete — $offset payments stored")
|
||||
NotificationHelper.notifySyncComplete(applicationContext, offset)
|
||||
return Result.success()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user