Skip to content

Commit

Permalink
Increase watchers intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubuid committed Feb 28, 2024
1 parent 0d240cb commit 570f163
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ internal class PairingEngine(
.onEach {
supervisorScope {
launch(Dispatchers.IO) {
resubscribeToPairing()
sendBatchSubcrbeForPairings()
}
}

Expand All @@ -279,6 +279,15 @@ internal class PairingEngine(
}.launchIn(scope)
}

private suspend fun sendBatchSubcrbeForPairings() {
try {
val pairingTopics = pairingRepository.getListOfPairings().filter { pairing -> pairing.isNotExpired() }.map { pairing -> pairing.topic.value }
jsonRpcInteractor.batchSubscribe(pairingTopics) { error -> scope.launch { internalErrorFlow.emit(SDKError(error)) } }
} catch (e: Exception) {
scope.launch { internalErrorFlow.emit(SDKError(e)) }
}
}

private fun inactivePairingsExpiryWatcher() {
repeatableFlow(WATCHER_INTERVAL)
.onEach {
Expand All @@ -298,9 +307,7 @@ internal class PairingEngine(
.onEach {
try {
pairingRepository.getListOfActivePairings()
.onEach { pairing ->
pairing.isNotExpired()
}
.onEach { pairing -> pairing.isNotExpired() }
} catch (e: Exception) {
logger.error(e)
}
Expand Down Expand Up @@ -341,15 +348,6 @@ internal class PairingEngine(
}
}.launchIn(scope)

private fun resubscribeToPairing() {
try {
val pairingTopics = runBlocking { pairingRepository.getListOfPairings().filter { pairing -> pairing.isNotExpired() }.map { pairing -> pairing.topic.value } }
jsonRpcInteractor.batchSubscribe(pairingTopics) { error -> scope.launch { internalErrorFlow.emit(SDKError(error)) } }
} catch (e: Exception) {
scope.launch { internalErrorFlow.emit(SDKError(e)) }
}
}

private suspend fun onPairingDelete(request: WCRequest, params: PairingParams.DeleteParams) {
val irnParams = IrnParams(Tags.PAIRING_DELETE_RESPONSE, Ttl(dayInSeconds))
try {
Expand Down Expand Up @@ -440,7 +438,7 @@ internal class PairingEngine(
pairingRepository.getPairingOrNullByTopic(Topic(topic))?.let { pairing -> return@let pairing.isNotExpired() } ?: false

companion object {
private const val WATCHER_INTERVAL = 5000L
private const val WATCHER_INTERVAL = 30000L //30s
private const val ACTIVE_PAIRINGS_WATCHER_INTERVAL = 600000L //10mins
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,6 @@ internal class SignEngine(
}

companion object {
private const val WATCHER_INTERVAL = 5000L
private const val WATCHER_INTERVAL = 30000L //30s
}
}

0 comments on commit 570f163

Please sign in to comment.