GODT-1468: Fix main windows status and add background context without retry.

This commit is contained in:
Jakub
2021-12-13 12:29:49 +01:00
parent 3bb9146d9f
commit d40fbda2ab
12 changed files with 101 additions and 112 deletions

View File

@ -30,20 +30,47 @@ var (
)
func (m *manager) pingUntilSuccess() {
if m.isPingOngoing() {
logrus.Debug("Ping already ongoing")
return
}
m.pingingStarted()
defer m.pingingStopped()
attempt := 0
for {
err := m.testPing(context.Background())
ctx := ContextWithoutRetry(context.Background())
err := m.testPing(ctx)
if err == nil {
return
}
waitTime := getRetryConnectionSleep(attempt)
attempt++
logrus.WithError(err).WithField("attempt", attempt).WithField("wait", waitTime).Debug("Connection not available")
logrus.WithError(err).WithField("attempt", attempt).WithField("wait", waitTime).Debug("Connection (still) not available")
time.Sleep(waitTime)
}
}
func (m *manager) isPingOngoing() bool {
m.pingMutex.RLock()
defer m.pingMutex.RUnlock()
return m.isPinging
}
func (m *manager) pingingStarted() {
m.pingMutex.Lock()
defer m.pingMutex.Unlock()
m.isPinging = true
}
func (m *manager) pingingStopped() {
m.pingMutex.Lock()
defer m.pingMutex.Unlock()
m.isPinging = false
}
func getRetryConnectionSleep(idx int) time.Duration {
if idx >= len(retryConnectionSleeps) {
idx = len(retryConnectionSleeps) - 1