Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Fix the Github automatic backup
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed Aug 29, 2023
1 parent 8128807 commit e7a0042
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package com.ivy.wallet.backup.github

import android.content.Context
import androidx.hilt.work.HiltWorker
import androidx.work.BackoffPolicy
import androidx.work.Constraints
import androidx.work.CoroutineWorker
import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.NetworkType
import androidx.work.PeriodicWorkRequest
import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager
import androidx.work.WorkerParameters
Expand All @@ -20,7 +22,6 @@ class GitHubAutoBackupManager @Inject constructor(
@ApplicationContext
private val context: Context
) {

private val uniqueWorkName = "GITHUB_AUTO_BACKUP_WORK"

fun scheduleAutoBackups() {
Expand All @@ -34,6 +35,11 @@ class GitHubAutoBackupManager @Inject constructor(
.setRequiredNetworkType(NetworkType.CONNECTED)
.build()
)
.setBackoffCriteria(
BackoffPolicy.EXPONENTIAL,
PeriodicWorkRequest.MIN_BACKOFF_MILLIS,
TimeUnit.MILLISECONDS
)
.build()

WorkManager.getInstance(context)
Expand Down Expand Up @@ -74,13 +80,20 @@ class GitHubBackupWorker @AssistedInject constructor(
@Assisted params: WorkerParameters,
private val gitHubBackup: GitHubBackup,
) : CoroutineWorker(appContext, params) {
companion object {
const val MAX_RETRIES = 7
}

override suspend fun doWork(): Result {
return gitHubBackup.backupData(
isAutomatic = true
).fold(
ifLeft = {
Result.failure()
if (runAttemptCount <= MAX_RETRIES) {
Result.retry()
} else {
Result.failure()
}
},
ifRight = {
Result.success()
Expand Down

0 comments on commit e7a0042

Please sign in to comment.