@@ -43,6 +43,7 @@ import java.util.concurrent.Semaphore
4343import kotlin.math.max
4444import kotlin.time.Duration
4545import kotlin.time.Duration.Companion.ZERO
46+ import kotlin.time.Duration.Companion.hours
4647import kotlin.time.Duration.Companion.minutes
4748import kotlin.time.Duration.Companion.seconds
4849import kotlin.time.DurationUnit
@@ -541,12 +542,23 @@ class AuthManager(private val cs: CoroutineScope) : Disposable {
541542
542543 refreshCounter++
543544
544- // send statistics
545+
546+ // Detect errors and send statistics
545547 val now = Clock .System .now()
546548 val timeSinceLastStatistics = (now - statisticsStartTime).inWholeMilliseconds.toDuration(DurationUnit .MILLISECONDS )
547- // if (timeSinceLastStatistics >= 1.hours) {
548- // /todo: temp change to 1 hour
549- if (timeSinceLastStatistics >= 20 .minutes) {
549+
550+ // detect too many refresh in a short time. in correct functioning there should never be more than 5 refresh in 1 hour
551+ if (refreshCounter > 5 && timeSinceLastStatistics < 1 .hours) {
552+ ErrorReporter .getInstance().reportError(
553+ " AuthManager.autoRefreshJob" , " too many refresh" , mapOf (
554+ " period.minutes" to timeSinceLastStatistics.inWholeMinutes,
555+ " refresh.counter" to refreshCounter
556+ )
557+ )
558+ }
559+
560+ // send statistics approximately every 1 hour , this will help detect incorrect functioning on this job.
561+ if (timeSinceLastStatistics >= 1 .hours) {
550562 statisticsStartTime = now
551563 reportAuthPosthogEvent(
552564 " AutoRefreshStats" , " AutoRefreshJob" , null , mapOf (
0 commit comments