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( SyncUseCase(
overviewStore, overviewStore,
SideEffectFlowIterator(logger), SideEffectFlowIterator(logger, errorTracker),
SyncSideEffects(keySharer, verificationHandler, deviceNotifier, messageDecrypter, json, oneTimeKeyProducer, logger), SyncSideEffects(keySharer, verificationHandler, deviceNotifier, messageDecrypter, json, oneTimeKeyProducer, logger),
httpClient, httpClient,
syncStore, syncStore,

View File

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