tracking and logging locally sync errors

This commit is contained in:
Adam Brown 2022-11-10 22:37:08 +00:00
parent 8885406a74
commit b8f60d804a
2 changed files with 7 additions and 5 deletions

View File

@ -76,7 +76,7 @@ internal class DefaultSyncService(
)
SyncUseCase(
overviewStore,
SideEffectFlowIterator(logger),
SideEffectFlowIterator(logger, errorTracker),
SyncSideEffects(keySharer, verificationHandler, deviceNotifier, messageDecrypter, json, oneTimeKeyProducer, logger),
httpClient,
syncStore,

View File

@ -1,12 +1,13 @@
package app.dapk.st.matrix.sync.internal
import app.dapk.st.core.extensions.ErrorTracker
import app.dapk.st.matrix.common.MatrixLogTag.SYNC
import app.dapk.st.matrix.common.MatrixLogger
import app.dapk.st.matrix.common.matrixLog
import kotlinx.coroutines.*
internal class SideEffectFlowIterator(private val logger: MatrixLogger) {
suspend fun <T> loop(initial: T?, onPost: suspend () -> Unit, onIteration: suspend (T?) -> T?) {
internal class SideEffectFlowIterator(private val logger: MatrixLogger, private val errorTracker: ErrorTracker) {
suspend fun <T> loop(initial: T?, onPost: suspend (Throwable?) -> Unit, onIteration: suspend (T?) -> T?) {
var previousState = initial
while (currentCoroutineContext().isActive) {
@ -15,11 +16,12 @@ internal class SideEffectFlowIterator(private val logger: MatrixLogger) {
previousState = withContext(NonCancellable) {
onIteration(previousState)
}
onPost()
onPost(null)
} catch (error: Throwable) {
logger.matrixLog(SYNC, "on loop error: ${error.message}")
error.printStackTrace()
errorTracker.track(error, "sync loop error")
delay(10000L)
onPost(error)
}
}
logger.matrixLog(SYNC, "isActive: ${currentCoroutineContext().isActive}")