Maybe don't create an infinite loop

This commit is contained in:
stryan 2022-09-01 13:36:33 -04:00
parent 2059932ad9
commit 8fc17bd9c9

21
nun.go
View File

@ -33,21 +33,22 @@ func (n *nunWatch) Main() {
case <-n.stop: case <-n.stop:
return return
case <-ticker.C: case <-ticker.C:
if n.fail > 5 {
log.Fatal("fail count too high; ending loop")
return
}
if n.fail > 3 {
log.Println("over three failures, increasing tick time by 5x")
ticker.Reset(5 * time.Duration(n.timer) * time.Minute)
break
}
newPost, err := getNewestPost("LittleNuns") newPost, err := getNewestPost("LittleNuns")
if err != nil { if err != nil {
log.Printf("error getting newest post: %v", err) log.Printf("error getting newest post: %v", err)
log.Println("skipping this cycle, incrementing fail count") log.Println("skipping this cycle, incrementing fail count")
n.fail++ n.fail++
break if n.fail > 5 {
log.Fatal("fail count too high; ending loop")
return
} else if n.fail > 3 {
log.Println("over three failures, increasing tick time by 5x")
ticker.Reset(5 * time.Duration(n.timer) * time.Minute)
break
} else {
break
}
} }
if n.fail != 0 { if n.fail != 0 {
n.fail = 0 n.fail = 0