From 2cbcb510b5f24654d6b7a4a63f147db36a967d55 Mon Sep 17 00:00:00 2001 From: Mike Cheng Date: Mon, 4 May 2015 20:52:57 -0400 Subject: [PATCH] Proper sleep logic when errors occur. Also better logging --- dyndns/daemon.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/dyndns/daemon.go b/dyndns/daemon.go index f1a92fb..557f3a2 100644 --- a/dyndns/daemon.go +++ b/dyndns/daemon.go @@ -32,7 +32,9 @@ func runConfig(c api.Config, daemon bool) { if err != nil { log.Logger.Print("Failed to retreive IP: ") if daemon { - log.Logger.Println("Will retry...") + log.Logger.Printf("Will retry in %d seconds...\n", c.Interval) + time.Sleep(time.Duration(c.Interval) * time.Second) + continue } else { log.Logger.Println("Giving up.") @@ -46,9 +48,11 @@ func runConfig(c api.Config, daemon bool) { // update it. records, err := a.GetDNSRecords(c.Domain) if err != nil { - log.Logger.Printf("Failed to retreive records for%s\n", c.Domain) + log.Logger.Printf("Failed to retreive records for %s:\n\t%s\n", c.Domain, err) if daemon { - log.Logger.Print("Will retry...") + log.Logger.Printf("Will retry in %d seconds...\n", c.Interval) + time.Sleep(time.Duration(c.Interval) * time.Second) + continue } else { log.Logger.Print("Giving up.") @@ -68,10 +72,12 @@ func runConfig(c api.Config, daemon bool) { } } + log.Logger.Println("Update complete.") if !daemon { log.Logger.Println("Non daemon mode, stopping.") return } + log.Logger.Printf("Will update again in %d seconds.\n", c.Interval) time.Sleep(time.Duration(c.Interval) * time.Second) }