mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-23 04:28:35 +00:00
Add custom 404 retry logic.
This commit is contained in:
@@ -27,6 +27,7 @@ import org.thoughtcrime.securesms.dependencies.AppDependencies
|
|||||||
import org.thoughtcrime.securesms.events.PartProgressEvent
|
import org.thoughtcrime.securesms.events.PartProgressEvent
|
||||||
import org.thoughtcrime.securesms.jobmanager.Job
|
import org.thoughtcrime.securesms.jobmanager.Job
|
||||||
import org.thoughtcrime.securesms.jobmanager.JobLogger.format
|
import org.thoughtcrime.securesms.jobmanager.JobLogger.format
|
||||||
|
import org.thoughtcrime.securesms.jobmanager.impl.BackoffUtil
|
||||||
import org.thoughtcrime.securesms.jobmanager.impl.BatteryNotLowConstraint
|
import org.thoughtcrime.securesms.jobmanager.impl.BatteryNotLowConstraint
|
||||||
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint
|
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint
|
||||||
import org.thoughtcrime.securesms.jobmanager.impl.RestoreAttachmentConstraint
|
import org.thoughtcrime.securesms.jobmanager.impl.RestoreAttachmentConstraint
|
||||||
@@ -47,6 +48,10 @@ import org.whispersystems.signalservice.api.push.exceptions.RangeException
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
import kotlin.math.max
|
||||||
|
import kotlin.math.pow
|
||||||
|
import kotlin.time.Duration.Companion.days
|
||||||
|
import kotlin.time.Duration.Companion.hours
|
||||||
import kotlin.time.Duration.Companion.milliseconds
|
import kotlin.time.Duration.Companion.milliseconds
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -197,8 +202,19 @@ class RestoreAttachmentJob private constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onShouldRetry(exception: Exception): Boolean {
|
override fun onShouldRetry(exception: Exception): Boolean {
|
||||||
return exception is PushNetworkException ||
|
return exception is PushNetworkException || exception is RetryLaterException
|
||||||
exception is RetryLaterException
|
}
|
||||||
|
|
||||||
|
override fun getNextRunAttemptBackoff(pastAttemptCount: Int, exception: java.lang.Exception): Long {
|
||||||
|
return if (exception is NonSuccessfulResponseCodeException && exception.code == 404) {
|
||||||
|
if (manual) {
|
||||||
|
BackoffUtil.exponentialBackoff(pastAttemptCount, 1.hours.inWholeMilliseconds)
|
||||||
|
} else {
|
||||||
|
1.days.inWholeMilliseconds * 2.0.pow(max(0.0, pastAttemptCount.toDouble()) - 1.0).toInt()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
super.getNextRunAttemptBackoff(pastAttemptCount, exception)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Throws(IOException::class, RetryLaterException::class)
|
@Throws(IOException::class, RetryLaterException::class)
|
||||||
@@ -284,12 +300,16 @@ class RestoreAttachmentJob private constructor(
|
|||||||
if (RemoteConfig.internalUser) {
|
if (RemoteConfig.internalUser) {
|
||||||
postFailedToDownloadFromArchiveNotification()
|
postFailedToDownloadFromArchiveNotification()
|
||||||
}
|
}
|
||||||
|
|
||||||
retrieveAttachment(messageId, attachmentId, attachment, true)
|
retrieveAttachment(messageId, attachmentId, attachment, true)
|
||||||
return
|
return
|
||||||
} else if (e.code == 401 && useArchiveCdn) {
|
} else if (e.code == 401 && useArchiveCdn) {
|
||||||
SignalStore.backup.mediaCredentials.cdnReadCredentials = null
|
SignalStore.backup.mediaCredentials.cdnReadCredentials = null
|
||||||
SignalStore.backup.cachedMediaCdnPath = null
|
SignalStore.backup.cachedMediaCdnPath = null
|
||||||
throw RetryLaterException(e)
|
throw RetryLaterException(e)
|
||||||
|
} else if (e.code == 404 && attachment.remoteLocation?.isNotBlank() == true) {
|
||||||
|
Log.i(TAG, "Failed to download attachment from transit tier. Scheduling retry.")
|
||||||
|
throw e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user