GoScrobble/internal/goscrobble/timers.go
Daniel Mason 9866dea36b
0.0.11
- Fix redirects to /login for auth required pages
- Add handling for 401/429 + No connection responses in API calls
- Add background workers for Go (clear out password resets)
- Fixed timezone issues
2021-04-02 22:24:00 +13:00

37 lines
597 B
Go

package goscrobble
import (
"fmt"
"time"
)
var endTicker chan bool
func StartBackgroundWorkers() {
endTicker := make(chan bool)
hourTicker := time.NewTicker(time.Hour)
minuteTicker := time.NewTicker(time.Duration(1) * time.Minute)
go func() {
for {
select {
case <-endTicker:
fmt.Println("Stopping background workers")
return
case <-hourTicker.C:
// Clear old password reset tokens
clearOldResetTokens()
case <-minuteTicker.C:
// Update playdata from spotify
updateSpotifyData()
}
}
}()
}
func EndBackgroundWorkers() {
endTicker <- true
}