|
|
@@ -2,6 +2,7 @@ package com.example.modifier.http.api
|
|
|
|
|
|
import android.util.Log
|
|
|
import com.example.modifier.baseTag
|
|
|
+import com.example.modifier.http.isTimeoutException
|
|
|
import com.example.modifier.http.ktorClient
|
|
|
import com.example.modifier.http.request.RcsNumberRequest
|
|
|
import com.example.modifier.http.response.RcsNumberResponse
|
|
|
@@ -9,6 +10,7 @@ import io.ktor.client.call.body
|
|
|
import io.ktor.client.plugins.resources.get
|
|
|
import io.ktor.client.plugins.resources.post
|
|
|
import io.ktor.client.plugins.resources.put
|
|
|
+import io.ktor.client.plugins.retry
|
|
|
import io.ktor.client.plugins.timeout
|
|
|
import io.ktor.client.request.setBody
|
|
|
import io.ktor.http.ContentType
|
|
|
@@ -19,6 +21,7 @@ import kotlinx.coroutines.coroutineScope
|
|
|
import kotlinx.coroutines.delay
|
|
|
import kotlinx.coroutines.launch
|
|
|
import kotlinx.coroutines.withTimeoutOrNull
|
|
|
+import kotlin.coroutines.cancellation.CancellationException
|
|
|
import kotlin.coroutines.coroutineContext
|
|
|
import kotlin.time.Duration.Companion.seconds
|
|
|
|
|
|
@@ -48,15 +51,32 @@ class RcsNumberApi() {
|
|
|
taskId = taskId,
|
|
|
country = pinCountry
|
|
|
)
|
|
|
- val response = ktorClient.put(
|
|
|
- RcsNumberApi()
|
|
|
- ) {
|
|
|
+ val response = ktorClient.put(RcsNumberApi()) {
|
|
|
contentType(ContentType.Application.Json)
|
|
|
setBody(req)
|
|
|
timeout {
|
|
|
requestTimeoutMillis = 60 * 1000
|
|
|
socketTimeoutMillis = 60 * 1000
|
|
|
}
|
|
|
+ retry {
|
|
|
+ maxRetries = 3600
|
|
|
+ retryOnExceptionIf { _, cause ->
|
|
|
+ when {
|
|
|
+ cause.isTimeoutException() -> true
|
|
|
+ cause is CancellationException -> false
|
|
|
+ else -> true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ retryIf { _, response ->
|
|
|
+ response.status.value.let {
|
|
|
+ when (it) {
|
|
|
+ 425, 429, 502, 503, 504 -> true
|
|
|
+ else -> false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ delayMillis { 1000 }
|
|
|
+ }
|
|
|
}
|
|
|
return response.body<RcsNumberResponse>()
|
|
|
}
|