add a retry

This commit is contained in:
davidnewhall2 2019-12-09 00:49:25 -08:00
parent 314417abc5
commit 24197c1ba3
1 changed files with 4 additions and 1 deletions

View File

@ -116,20 +116,23 @@ func (u *UnifiPoller) Run() error {
// PollController runs forever, polling UniFi and pushing to InfluxDB
// This is started by Run() or RunBoth() after everything checks out.
func (u *UnifiPoller) PollController() {
var tryAgain bool
interval := u.Config.Interval.Round(time.Second)
log.Printf("[INFO] Everything checks out! Poller started, InfluxDB interval: %v", interval)
ticker := time.NewTicker(interval)
for u.LastCheck = range ticker.C {
// Some users need to re-auth every interval because the cookie times out.
if u.Config.ReAuth {
if u.Config.ReAuth || tryAgain {
u.LogDebugf("Re-authenticating to UniFi Controller")
if err := u.Unifi.Login(); err != nil {
u.LogErrorf("%v", err)
continue
}
tryAgain = false
}
if err := u.CollectAndProcess(); err != nil {
u.LogErrorf("%v", err)
tryAgain = true
}
}
}