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-11 08:10:52 +00:00
|
|
|
user, _ := getUserByUsername("idanoo")
|
|
|
|
go user.updateImageDataFromSpotify()
|
|
|
|
|
2021-04-02 09:24:00 +00:00
|
|
|
endTicker := make(chan bool)
|
|
|
|
|
2021-04-08 08:46:31 +00:00
|
|
|
hourTicker := time.NewTicker(time.Duration(1) * 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
|
2021-04-09 21:49:32 +00:00
|
|
|
go clearOldResetTokens()
|
2021-04-02 09:24:00 +00:00
|
|
|
|
2021-04-08 08:46:31 +00:00
|
|
|
// Attempt to pull missing images from spotify - hackerino version!
|
|
|
|
user, _ := getUserByUsername("idanoo")
|
2021-04-09 21:49:32 +00:00
|
|
|
go user.updateImageDataFromSpotify()
|
2021-04-02 09:24:00 +00:00
|
|
|
case <-minuteTicker.C:
|
2021-04-09 21:49:32 +00:00
|
|
|
// Update playdata from Spotify
|
|
|
|
go updateSpotifyData()
|
|
|
|
|
|
|
|
// Update playdate from Navidrome
|
|
|
|
go updateNavidromeData()
|
2021-04-02 09:24:00 +00:00
|
|
|
}
|
2021-04-01 12:56:08 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
2021-04-02 09:24:00 +00:00
|
|
|
|
|
|
|
func EndBackgroundWorkers() {
|
|
|
|
endTicker <- true
|
|
|
|
}
|