2021-04-01 12:56:08 +00:00
|
|
|
package goscrobble
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2021-04-02 09:24:00 +00:00
|
|
|
var endTicker chan bool
|
|
|
|
|
|
|
|
func StartBackgroundWorkers() {
|
2021-04-03 01:16:13 +00:00
|
|
|
updateSpotifyData()
|
|
|
|
|
2021-04-02 09:24:00 +00:00
|
|
|
endTicker := make(chan bool)
|
|
|
|
|
|
|
|
hourTicker := time.NewTicker(time.Hour)
|
2021-04-08 07:50:43 +00:00
|
|
|
minuteTicker := time.NewTicker(time.Duration(60) * time.Second)
|
2021-04-02 09:24:00 +00:00
|
|
|
|
2021-04-01 12:56:08 +00:00
|
|
|
go func() {
|
2021-04-02 09:24:00 +00:00
|
|
|
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()
|
|
|
|
}
|
2021-04-01 12:56:08 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
2021-04-02 09:24:00 +00:00
|
|
|
|
|
|
|
func EndBackgroundWorkers() {
|
|
|
|
endTicker <- true
|
|
|
|
}
|