@@ -15,14 +15,18 @@ import org.digma.intellij.plugin.log.Log
1515import org.digma.intellij.plugin.model.rest.AboutResult
1616import org.digma.intellij.plugin.persistence.PersistenceService
1717import org.digma.intellij.plugin.posthog.ActivityMonitor
18+ import org.digma.intellij.plugin.scheduling.disposingOneShotDelayedTask
1819import org.digma.intellij.plugin.scheduling.disposingPeriodicTask
1920import org.digma.intellij.plugin.scheduling.oneShotTask
2021import java.util.concurrent.atomic.AtomicReference
22+ import kotlin.jvm.Throws
2123import 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.
2528 */
29+ // TODO: convert backend info to application service
2630@Service(Service .Level .PROJECT )
2731class BackendInfoHolder (val project : Project ) : DisposableAdaptor {
2832
@@ -127,8 +131,26 @@ class BackendInfoHolder(val project: Project) : DisposableAdaptor {
127131 }
128132
129133
130- // must be called in background coroutine
134+ // must be called in background coroutine.
135+ // if failed update will try again after 5 seconds
131136 private fun update () {
137+ try {
138+ updateImpl()
139+ } catch (e: Throwable ) {
140+ Log .log(logger::trace, " update failed trying again in 5 seconds" )
141+ // if update fails run another try after 2 seconds. maybe it was a momentary error from AnalyticsService.
142+ // if that will not succeed there will be another periodic update soon
143+ disposingOneShotDelayedTask(" BackendInfoHolder.update-fallback" , 5 .seconds.inWholeMilliseconds) {
144+ Log .log(logger::trace, " calling updateImpl after 5 seconds delay" )
145+ updateImpl()
146+ }
147+ }
148+ }
149+
150+
151+ // Note that updateImpl rethrows exceptions
152+ @Throws(Throwable ::class )
153+ private fun updateImpl (){
132154 try {
133155 if (isProjectValid(project)) {
134156 Log .log(logger::trace, " updating backend info" )
@@ -139,16 +161,12 @@ class BackendInfoHolder(val project: Project) : DisposableAdaptor {
139161 Log .log(logger::trace, " backend info updated {}" , aboutRef.get())
140162 }
141163 } catch (e: Throwable ) {
142- Log .warnWithException(logger, project, e, " error in update" )
164+ Log .warnWithException(logger, project, e, " error in update {} " ,e )
143165 val isConnectionException = ExceptionUtils .isAnyConnectionException(e)
144166 if (! isConnectionException) {
145167 ErrorReporter .getInstance().reportError(project, " BackendInfoHolder.update" , e)
146168 }
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-
169+ throw e;
152170 }
153171 }
154172
0 commit comments