From 0d013bfe280d8e4320421fe737c10c9e14b50569 Mon Sep 17 00:00:00 2001 From: Steve Date: Tue, 2 Aug 2022 13:02:12 -0400 Subject: [PATCH] custom backoff timer --- main.go | 2 +- nun.go | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 0debdad..3978ad2 100644 --- a/main.go +++ b/main.go @@ -69,7 +69,7 @@ func main() { stop <- true }() - nun := newNunWatch(stop, matrixClient) + nun := newNunWatch(stop, matrixClient, 2) wg.Add(1) go func() { diff --git a/nun.go b/nun.go index 9c4f9f0..5158046 100644 --- a/nun.go +++ b/nun.go @@ -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")