custom backoff timer

This commit is contained in:
stryan 2022-08-02 13:02:12 -04:00
parent 24c84dce0f
commit 0d013bfe28
2 changed files with 7 additions and 6 deletions

View File

@ -69,7 +69,7 @@ func main() {
stop <- true
}()
nun := newNunWatch(stop, matrixClient)
nun := newNunWatch(stop, matrixClient, 2)
wg.Add(1)
go func() {

11
nun.go
View File

@ -13,14 +13,15 @@ type nunWatch struct {
curPost post
stop chan bool
client *mautrix.Client
timer int
}
func newNunWatch(stop chan bool, c *mautrix.Client) *nunWatch {
return &nunWatch{0, post{}, stop, c}
func newNunWatch(stop chan bool, c *mautrix.Client, t int) *nunWatch {
return &nunWatch{0, post{}, stop, c, t}
}
func (n *nunWatch) Main() {
ticker := time.NewTicker(60 * time.Second)
ticker := time.NewTicker(time.Duration(n.timer) * time.Minute)
for {
select {
@ -32,8 +33,8 @@ func (n *nunWatch) Main() {
return
}
if n.fail > 3 {
log.Println("over three failures, increasing tick time to 5 minutes")
ticker.Reset(5 * time.Minute)
log.Println("over three failures, increasing tick time by 5x")
ticker.Reset(5 * time.Duration(n.timer) * time.Minute)
continue
}
newPost, err := getNewestPost("LittleNuns")