Skip to content
Snippets Groups Projects
Unverified Commit 4b0b5910 authored by Mert Safter's avatar Mert Safter Committed by GitHub
Browse files

Make transaction timeout settable per transaction. Increase Risk Leve… (#1227)

* Make transaction timeout settable per transaction. Increase Risk Level Calc transaction

* Make timeout more readable
parent 1f160043
No related branches found
No related tags found
No related merge requests found
......@@ -135,6 +135,12 @@ object RiskLevelTransaction : Transaction() {
// Injecting here will break Test
private val riskLevelCalculation: RiskLevelCalculation = DefaultRiskLevelCalculation()
/**
* The maximal runtime of the Risk Level transaction
* In milliseconds
*/
private const val RISK_LEVEL_TRANSACTION_TIMEOUT = 480 * 1000L
// @Inject lateinit var riskScoreAnalysis: RiskScoreAnalysis
// TODO pass instance of this to constructor as soon as RiskLevelTransaction is converted to a class
// Injecting here will break Test
......@@ -190,7 +196,10 @@ object RiskLevelTransaction : Transaction() {
}
/** initiates the transaction. This suspend function guarantees a successful transaction once completed. */
suspend fun start() = lockAndExecute(scope = transactionScope) {
suspend fun start() = lockAndExecute(
scope = transactionScope,
timeout = RISK_LEVEL_TRANSACTION_TIMEOUT
) {
/****************************************************
* CHECK [NO_CALCULATION_POSSIBLE_TRACING_OFF] CONDITIONS
****************************************************/
......
......@@ -49,15 +49,6 @@ import kotlin.system.measureTimeMillis
*/
abstract class Transaction {
companion object {
/**
* Transaction Timeout in Milliseconds, used to cancel any Transactions that run into never ending execution
* (e.g. due to a coroutine not being cancelled properly or an exception leading to unchecked behavior)
*/
private val TRANSACTION_TIMEOUT_MS: Long
get() = TimeVariables.getTransactionTimeout()
}
@Suppress("VariableNaming", "PropertyName") // Done as the Convention is TAG for every class
abstract val TAG: String?
......@@ -189,6 +180,7 @@ abstract class Transaction {
*
* @param unique Executes the transaction as Unique. This results in the next execution being omitted in case of a race towards the lock.
* @param block the suspending function that should be used to execute the transaction.
* @param timeout the timeout for the transcation (in milliseconds)
* @throws TransactionException the exception that wraps around any error that occurs inside the lock.
*
* @see executeState
......@@ -197,6 +189,7 @@ abstract class Transaction {
suspend fun lockAndExecute(
unique: Boolean = false,
scope: CoroutineScope,
timeout: Long = TimeVariables.getTransactionTimeout(),
block: suspend CoroutineScope.() -> Unit
) {
......@@ -213,7 +206,7 @@ abstract class Transaction {
executeState(INIT) { transactionId.set(UUID.randomUUID()) }
val duration = measureTimeMillis {
withTimeout(TRANSACTION_TIMEOUT_MS) {
withTimeout(timeout) {
block.invoke(this)
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment