Skip to content

Commit dfa1084

Browse files
committed
improve auto refresh job
1 parent 143e16f commit dfa1084

File tree

1 file changed

+16
-4
lines changed
  • ide-common/src/main/kotlin/org/digma/intellij/plugin/auth

1 file changed

+16
-4
lines changed

ide-common/src/main/kotlin/org/digma/intellij/plugin/auth/AuthManager.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import java.util.concurrent.Semaphore
4343
import kotlin.math.max
4444
import kotlin.time.Duration
4545
import kotlin.time.Duration.Companion.ZERO
46+
import kotlin.time.Duration.Companion.hours
4647
import kotlin.time.Duration.Companion.minutes
4748
import kotlin.time.Duration.Companion.seconds
4849
import 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

Comments
 (0)