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 stop <- true
}() }()
nun := newNunWatch(stop, matrixClient) nun := newNunWatch(stop, matrixClient, 2)
wg.Add(1) wg.Add(1)
go func() { go func() {

11
nun.go
View File

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