Proper sleep logic when errors occur. Also better logging

This commit is contained in:
Mike Cheng 2015-05-04 20:52:57 -04:00
parent e18f181cde
commit 2cbcb510b5

View file

@ -32,7 +32,9 @@ func runConfig(c api.Config, daemon bool) {
if err != nil { if err != nil {
log.Logger.Print("Failed to retreive IP: ") log.Logger.Print("Failed to retreive IP: ")
if daemon { 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 continue
} else { } else {
log.Logger.Println("Giving up.") log.Logger.Println("Giving up.")
@ -46,9 +48,11 @@ func runConfig(c api.Config, daemon bool) {
// update it. // update it.
records, err := a.GetDNSRecords(c.Domain) records, err := a.GetDNSRecords(c.Domain)
if err != nil { 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 { 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 continue
} else { } else {
log.Logger.Print("Giving up.") log.Logger.Print("Giving up.")
@ -68,10 +72,12 @@ func runConfig(c api.Config, daemon bool) {
} }
} }
log.Logger.Println("Update complete.")
if !daemon { if !daemon {
log.Logger.Println("Non daemon mode, stopping.") log.Logger.Println("Non daemon mode, stopping.")
return return
} }
log.Logger.Printf("Will update again in %d seconds.\n", c.Interval)
time.Sleep(time.Duration(c.Interval) * time.Second) time.Sleep(time.Duration(c.Interval) * time.Second)
} }