TP-52887 | Add workerType to PreSignedUrlRequest (#10026)
This commit is contained in:
@@ -1,3 +1,10 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright © 2024 by Navi Technologies Limited
|
||||
* * All rights reserved. Strictly confidential
|
||||
*
|
||||
*/
|
||||
|
||||
package com.naviapp.manager
|
||||
|
||||
import android.content.Context
|
||||
@@ -23,19 +30,18 @@ import com.naviapp.utils.Constants.SOURCE
|
||||
import com.naviapp.utils.Constants.SUCCESS_CAPITAL
|
||||
import com.naviapp.utils.Constants.WORKER_TYPE
|
||||
import com.naviapp.utils.SmsUtil.extractTasks
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.awaitAll
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
/**
|
||||
* The worker is responsible for uploading user data to server.
|
||||
* Flows using the worker -
|
||||
* The worker is responsible for uploading user data to server. Flows using the worker -
|
||||
* 1. Home Page data upload.
|
||||
* 2. Offer Generation data upload.
|
||||
* 3. Background Periodic worker initiated in NewDashboardActivity.
|
||||
* The retry mechanism is available for the api failures and retry config is passed in the bundle.
|
||||
* 3. Background Periodic worker initiated in NewDashboardActivity. The retry mechanism is available
|
||||
* for the api failures and retry config is passed in the bundle.
|
||||
*/
|
||||
class RetryableUserDataUploadWorker(val context: Context, workerParams: WorkerParameters) :
|
||||
CoroutineWorker(context, workerParams) {
|
||||
@@ -45,6 +51,7 @@ class RetryableUserDataUploadWorker(val context: Context, workerParams: WorkerPa
|
||||
private var attemptToSendData = AtomicBoolean(true)
|
||||
private var failureResult: Result? = null
|
||||
private lateinit var userDataUploadWorkerConfig: UserDataUploadWorkerConfig
|
||||
|
||||
override suspend fun doWork(): Result {
|
||||
initData()
|
||||
initEventTracker()
|
||||
@@ -55,12 +62,13 @@ class RetryableUserDataUploadWorker(val context: Context, workerParams: WorkerPa
|
||||
|
||||
private fun initData() {
|
||||
inputData.apply {
|
||||
userDataUploadWorkerConfig = UserDataUploadWorkerConfig(
|
||||
sourceScreenName = getString(SOURCE).orElse(DEFAULT),
|
||||
allowedRetryCount = getInt(Constants.RETRY_COUNT, DEFAULT_WORKER_RETRY_COUNT),
|
||||
apiFailureRetryRequired = getBoolean(API_FAILURE_RETRY_REQUIRED, false),
|
||||
workerType = getString(WORKER_TYPE).orElse(DEFAULT)
|
||||
)
|
||||
userDataUploadWorkerConfig =
|
||||
UserDataUploadWorkerConfig(
|
||||
sourceScreenName = getString(SOURCE).orElse(DEFAULT),
|
||||
allowedRetryCount = getInt(Constants.RETRY_COUNT, DEFAULT_WORKER_RETRY_COUNT),
|
||||
apiFailureRetryRequired = getBoolean(API_FAILURE_RETRY_REQUIRED, false),
|
||||
workerType = getString(WORKER_TYPE).orElse(DEFAULT)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,10 +77,11 @@ class RetryableUserDataUploadWorker(val context: Context, workerParams: WorkerPa
|
||||
}
|
||||
|
||||
private fun initEventTracker() {
|
||||
eventTracker = NaviAnalytics.naviAnalytics.BaseUserDataUploadWorker(
|
||||
userDataUploadWorkerConfig.sourceScreenName,
|
||||
userDataUploadWorkerConfig.workerType
|
||||
)
|
||||
eventTracker =
|
||||
NaviAnalytics.naviAnalytics.BaseUserDataUploadWorker(
|
||||
userDataUploadWorkerConfig.sourceScreenName,
|
||||
userDataUploadWorkerConfig.workerType
|
||||
)
|
||||
}
|
||||
|
||||
private suspend fun uploadUserData() {
|
||||
@@ -82,11 +91,12 @@ class RetryableUserDataUploadWorker(val context: Context, workerParams: WorkerPa
|
||||
PreSignedUrlRequest(
|
||||
deviceId = deviceId,
|
||||
dataIngestionTypeList =
|
||||
listOf(
|
||||
IngestionType.SMS.name,
|
||||
IngestionType.CONTACTS.name,
|
||||
IngestionType.APPS.name
|
||||
)
|
||||
listOf(
|
||||
IngestionType.SMS.name,
|
||||
IngestionType.CONTACTS.name,
|
||||
IngestionType.APPS.name
|
||||
),
|
||||
workerType = userDataUploadWorkerConfig.workerType
|
||||
)
|
||||
)
|
||||
val data = response.data
|
||||
@@ -97,9 +107,7 @@ class RetryableUserDataUploadWorker(val context: Context, workerParams: WorkerPa
|
||||
handleAPIFailure(response.error ?: response.errors)
|
||||
sendEventTracker(
|
||||
UserDataUploadWorkerUseCase.PL_ERROR_IN_GETTING_PRESIGNED_URL,
|
||||
mapOf(
|
||||
"error" to (response.error ?: response.errors).toString()
|
||||
)
|
||||
mapOf("error" to (response.error ?: response.errors).toString())
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -110,19 +118,13 @@ class RetryableUserDataUploadWorker(val context: Context, workerParams: WorkerPa
|
||||
if (retryCount >= userDataUploadWorkerConfig.allowedRetryCount) {
|
||||
sendEventTracker(
|
||||
UserDataUploadWorkerUseCase.on_data_upload_retry_count_finished,
|
||||
mapOf(
|
||||
"retryCount" to retryCount.toString(),
|
||||
"error" to error.toString()
|
||||
)
|
||||
mapOf("retryCount" to retryCount.toString(), "error" to error.toString())
|
||||
)
|
||||
failureResult = Result.failure()
|
||||
} else {
|
||||
sendEventTracker(
|
||||
UserDataUploadWorkerUseCase.on_data_upload_retry_on_api_failure,
|
||||
mapOf(
|
||||
"retryCount" to retryCount.toString(),
|
||||
"error" to error.toString()
|
||||
)
|
||||
mapOf("retryCount" to retryCount.toString(), "error" to error.toString())
|
||||
)
|
||||
failureResult = Result.retry()
|
||||
}
|
||||
@@ -133,17 +135,19 @@ class RetryableUserDataUploadWorker(val context: Context, workerParams: WorkerPa
|
||||
apiPollScheduler =
|
||||
ApiPollScheduler(
|
||||
numberOfRetry =
|
||||
uploadDataAsyncResponse.requestConfig
|
||||
?.numOfRetries
|
||||
.orElse(Constants.API_POLL_RETRY_COUNT),
|
||||
uploadDataAsyncResponse.requestConfig
|
||||
?.numOfRetries
|
||||
.orElse(Constants.API_POLL_RETRY_COUNT),
|
||||
pollInterval =
|
||||
uploadDataAsyncResponse.requestConfig
|
||||
?.interval
|
||||
?.toLong()
|
||||
.orElse(Constants.API_POLL_REPEAT_PERIOD_SECONDS)
|
||||
uploadDataAsyncResponse.requestConfig
|
||||
?.interval
|
||||
?.toLong()
|
||||
.orElse(Constants.API_POLL_REPEAT_PERIOD_SECONDS)
|
||||
) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
sendEventTracker(UserDataUploadWorkerUseCase.PL_GET_PRE_SIGNED_URL_POLLING_SUCCESS)
|
||||
sendEventTracker(
|
||||
UserDataUploadWorkerUseCase.PL_GET_PRE_SIGNED_URL_POLLING_SUCCESS
|
||||
)
|
||||
sendData(uploadDataAsyncResponse = uploadDataAsyncResponse, scope = this)
|
||||
}
|
||||
}
|
||||
@@ -160,16 +164,16 @@ class RetryableUserDataUploadWorker(val context: Context, workerParams: WorkerPa
|
||||
val response = repository.getSigningData(it)
|
||||
if (
|
||||
response.data?.status.orEmpty() == SUCCESS_CAPITAL &&
|
||||
response.error == null &&
|
||||
response.errors.isNullOrEmpty()
|
||||
response.error == null &&
|
||||
response.errors.isNullOrEmpty()
|
||||
) {
|
||||
val list =
|
||||
extractTasks(
|
||||
response.data?.details?.innerData,
|
||||
scope,
|
||||
userDataUploadWorkerConfig.workerType,
|
||||
userDataUploadWorkerConfig.sourceScreenName
|
||||
)
|
||||
response.data?.details?.innerData,
|
||||
scope,
|
||||
userDataUploadWorkerConfig.workerType,
|
||||
userDataUploadWorkerConfig.sourceScreenName
|
||||
)
|
||||
.awaitAll()
|
||||
.filterNotNull()
|
||||
apiPollScheduler?.stopApiPoll()
|
||||
@@ -187,9 +191,7 @@ class RetryableUserDataUploadWorker(val context: Context, workerParams: WorkerPa
|
||||
list
|
||||
)
|
||||
} else {
|
||||
handleAPIFailure(
|
||||
response.error ?: response.errors
|
||||
)
|
||||
handleAPIFailure(response.error ?: response.errors)
|
||||
sendEventWithIndigestionList(
|
||||
UserDataUploadWorkerUseCase.on_data_upload_acknowledgement_failure,
|
||||
list
|
||||
@@ -213,10 +215,7 @@ class RetryableUserDataUploadWorker(val context: Context, workerParams: WorkerPa
|
||||
}
|
||||
|
||||
private fun sendEventWithIndigestionList(eventName: String, list: List<IngestionStatus>) {
|
||||
sendEventTracker(
|
||||
eventName,
|
||||
mapOf("ingestionList" to list.toString())
|
||||
)
|
||||
sendEventTracker(eventName, mapOf("ingestionList" to list.toString()))
|
||||
}
|
||||
|
||||
companion object {
|
||||
@@ -224,4 +223,4 @@ class RetryableUserDataUploadWorker(val context: Context, workerParams: WorkerPa
|
||||
const val DEFAULT_WORKER_RETRY_COUNT = 3
|
||||
const val API_FAILURE_RETRY_REQUIRED = "API_FAILURE_RETRY_REQUIRED"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright © 2024 by Navi Technologies Limited
|
||||
* * All rights reserved. Strictly confidential
|
||||
*
|
||||
*/
|
||||
|
||||
package com.naviapp.models.request
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class PreSignedUrlRequest(
|
||||
@SerializedName("deviceId") val deviceId: String? = null,
|
||||
@SerializedName("dataIngestionTypeList") val dataIngestionTypeList: List<String>? = null
|
||||
@SerializedName("dataIngestionTypeList") val dataIngestionTypeList: List<String>? = null,
|
||||
@SerializedName("workerType") val workerType: String? = null,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user