diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/transaction/RiskLevelTransaction.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/transaction/RiskLevelTransaction.kt index 4629e0eb7f3139d8b30b26fc406d71befb4fcfda..e11e39327da89cf50b63ec56ca872a211aeba5e6 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/transaction/RiskLevelTransaction.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/transaction/RiskLevelTransaction.kt @@ -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 ****************************************************/ diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/transaction/Transaction.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/transaction/Transaction.kt index a732d93fbffe2a7a41010b207d149501e427f0c1..e206e1a2a8b7148c6ae6306fb392e9556571a456 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/transaction/Transaction.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/transaction/Transaction.kt @@ -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) } }