Skip to content

Commit a46cf8d

Browse files
committed
fix-update-loop-in-backend-info-holder
1 parent 10cb6f5 commit a46cf8d

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

ide-common/src/main/kotlin/org/digma/intellij/plugin/analytics/BackendInfoHolder.kt

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ import org.digma.intellij.plugin.log.Log
1515
import org.digma.intellij.plugin.model.rest.AboutResult
1616
import org.digma.intellij.plugin.persistence.PersistenceService
1717
import org.digma.intellij.plugin.posthog.ActivityMonitor
18+
import org.digma.intellij.plugin.scheduling.disposingOneShotDelayedTask
1819
import org.digma.intellij.plugin.scheduling.disposingPeriodicTask
1920
import org.digma.intellij.plugin.scheduling.oneShotTask
2021
import java.util.concurrent.atomic.AtomicReference
22+
import kotlin.jvm.Throws
2123
import kotlin.time.Duration.Companion.minutes
24+
import kotlin.time.Duration.Companion.seconds
2225

2326
/**
2427
* keep the backend info and tracks it on connection events.
@@ -127,8 +130,24 @@ class BackendInfoHolder(val project: Project) : DisposableAdaptor {
127130
}
128131

129132

130-
//must be called in background coroutine
133+
//must be called in background coroutine.
134+
//if failed update will try again after 5 seconds
131135
private fun update() {
136+
try {
137+
updateImpl()
138+
} catch (e: Throwable) {
139+
//if update fails run another try after 2 seconds. maybe it was a momentary error from AnalyticsService.
140+
// if that will not succeed there will be another periodic update soon
141+
disposingOneShotDelayedTask("BackendInfoHolder.update-fallack", 5.seconds.inWholeMilliseconds) {
142+
updateImpl()
143+
}
144+
}
145+
}
146+
147+
148+
//Note that updateImpl rethrows exceptions
149+
@Throws(Throwable::class)
150+
private fun updateImpl(){
132151
try {
133152
if (isProjectValid(project)) {
134153
Log.log(logger::trace, "updating backend info")
@@ -144,11 +163,7 @@ class BackendInfoHolder(val project: Project) : DisposableAdaptor {
144163
if (!isConnectionException) {
145164
ErrorReporter.getInstance().reportError(project, "BackendInfoHolder.update", e)
146165
}
147-
148-
//if update fails run another try immediately. maybe it was a momentary error from AnalyticsService.
149-
// if that will not succeed then the next execution in 1 minute will hopefully succeed
150-
updateInBackground()
151-
166+
throw e;
152167
}
153168
}
154169

0 commit comments

Comments
 (0)