NTP-7108 | Add Money Manager feature to the SuperApp (#12804)
Signed-off-by: namankhurmi <naman.khurmi@navi.com> Signed-off-by: kishan kumar <kishan.kumar@navi.com> Co-authored-by: Sanjay P <sanjay.p@navi.com> Co-authored-by: Venkat Praneeth Reddy <venkat.praneeth@navi.com> Co-authored-by: Naman Khurmi <naman.khurmi@navi.com> Co-authored-by: Ankit Yadav <ankit.yadav@navi.com> Co-authored-by: Hitesh Kumar <hitesh.kumar@navi.com> Co-authored-by: nikhil kumar <nikhil.kumar@navi.com> Co-authored-by: Abhinav Gupta <abhinav.g@navi.com> Co-authored-by: Kishan Kumar <kishan.kumar@navi.com> Co-authored-by: Soumya Ranjan Patra <soumya.ranjan@navi.com> Co-authored-by: Girish Suragani <girish.suragani@navi.com> Co-authored-by: Aparna Vadlamani <aparna.vadlamani@navi.com> Co-authored-by: Siddiboina Susai <siddiboina.susai@navi.com> Co-authored-by: Ayushman Sharma <ayushman.sharma@navi.com> Co-authored-by: Kamalesh Garnayak <kamalesh.garnayak@navi.com>
This commit is contained in:
@@ -37,7 +37,6 @@ import com.navi.ap.network.model.ApplicationRequestBody
|
||||
import com.navi.ap.network.model.FillApplicationRequestBody
|
||||
import com.navi.ap.network.model.getBottomSheetStructure
|
||||
import com.navi.ap.utils.EventUtil
|
||||
import com.navi.ap.utils.PeriodicTaskScheduler
|
||||
import com.navi.ap.utils.bundleToMap
|
||||
import com.navi.ap.utils.constants.APP_ACTION
|
||||
import com.navi.ap.utils.constants.APP_CONFIG_VERSION
|
||||
@@ -75,6 +74,7 @@ import com.navi.base.utils.orFalse
|
||||
import com.navi.common.constants.API_SUCCESS_CODE
|
||||
import com.navi.common.network.ApiConstants
|
||||
import com.navi.common.network.models.isSuccessWithData
|
||||
import com.navi.common.scheduler.PeriodicTaskScheduler
|
||||
import com.navi.common.uitron.model.action.AnalyticsActionV2
|
||||
import com.navi.common.uitron.model.action.AnalyticsActionV2.PredefinedEventProperty
|
||||
import com.navi.common.uitron.model.action.FillApiData
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright © 2023-2024 by Navi Technologies Limited
|
||||
* * All rights reserved. Strictly confidential
|
||||
*
|
||||
*/
|
||||
|
||||
package com.navi.ap.utils
|
||||
|
||||
import com.navi.base.utils.orFalse
|
||||
import com.navi.common.utils.Constants.ERROR_MESSAGE
|
||||
import com.navi.common.utils.log
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.CoroutineExceptionHandler
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* To schedule any task periodically, Use this scheduler. It has coroutine based implementation.
|
||||
* Avoid using ApiPollScheduler (due to thread based implementation)
|
||||
*/
|
||||
class PeriodicTaskScheduler(
|
||||
private val initialDelaySeconds: Long = INITIAL_DELAY_FOR_PERIODIC_TASK_SECONDS,
|
||||
private val taskIntervalSeconds: Long = TASK_REPEAT_INTERVAL_SECONDS,
|
||||
private val maxAttempts: Int = TASK_RETRY_COUNT,
|
||||
private val onTimeout: (() -> Unit)? = null,
|
||||
private val task: () -> Unit
|
||||
) {
|
||||
|
||||
private var job: Job? = null
|
||||
private val exceptionHandler = CoroutineExceptionHandler { _, throwable ->
|
||||
val exception: Exception? = throwable.cause as? Exception
|
||||
exception?.log()
|
||||
}
|
||||
|
||||
private fun scheduleTask(): Flow<Unit> = flow {
|
||||
try {
|
||||
delay(initialDelaySeconds * 1000)
|
||||
repeat(maxAttempts) {
|
||||
if (job?.isActive.orFalse()) {
|
||||
task()
|
||||
delay(taskIntervalSeconds * 1000)
|
||||
emit(Unit)
|
||||
}
|
||||
}
|
||||
onTimeout?.invoke()
|
||||
} catch (e: Exception) {
|
||||
logApEvent(
|
||||
Pair(ERROR_MESSAGE, e.message.orEmpty()),
|
||||
eventName = COROUTINE_JOB_ON_COMPLETION_CALLED
|
||||
)
|
||||
e.log()
|
||||
}
|
||||
}
|
||||
|
||||
fun startTask(
|
||||
coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO,
|
||||
onResult: (() -> Unit)? = null
|
||||
) {
|
||||
stopTask()
|
||||
job =
|
||||
CoroutineScope(coroutineDispatcher + exceptionHandler)
|
||||
.launch { scheduleTask().collect { onResult?.invoke() } }
|
||||
.apply {
|
||||
invokeOnCompletion {
|
||||
val exception: Exception? = it?.cause as? Exception
|
||||
logApEvent(
|
||||
Pair(ERROR_MESSAGE, exception?.message.orEmpty()),
|
||||
eventName = COROUTINE_JOB_ON_COMPLETION_CALLED
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun stopTask() {
|
||||
if (job?.isActive.orFalse()) {
|
||||
job?.cancel()
|
||||
job = null
|
||||
}
|
||||
}
|
||||
|
||||
fun isJobActive() = job?.isActive.orFalse()
|
||||
|
||||
companion object {
|
||||
const val INITIAL_DELAY_FOR_PERIODIC_TASK_SECONDS = 5L
|
||||
const val TASK_REPEAT_INTERVAL_SECONDS = 10L
|
||||
const val TASK_RETRY_COUNT = 24
|
||||
const val COROUTINE_JOB_ON_COMPLETION_CALLED = "COROUTINE_JOB_ON_COMPLETION_CALLED"
|
||||
}
|
||||
}
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
package com.navi.ap.utils.helper
|
||||
|
||||
import com.navi.ap.utils.PeriodicTaskScheduler
|
||||
import com.navi.ap.utils.constants.AP_POLL_INITIAL_DELAY
|
||||
import com.navi.ap.utils.constants.AP_POLL_INTERVAL
|
||||
import com.navi.ap.utils.constants.AP_POLL_RETRY_COUNT
|
||||
import com.navi.common.scheduler.PeriodicTaskScheduler
|
||||
import com.navi.uitron.utils.orVal
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
|
||||
Reference in New Issue
Block a user