Improved jobs

This commit is contained in:
2018-03-21 05:15:03 +01:00
parent 71d6ba9848
commit 18cca18ebe
8 changed files with 28 additions and 20 deletions

View File

@ -7,26 +7,34 @@ import (
"github.com/fatih/color"
)
var ticker = time.NewTicker(500 * time.Millisecond)
func main() {
color.Yellow("Refreshing osu information")
defer color.Green("Finished.")
defer arn.Node.Close()
ticker := time.NewTicker(500 * time.Millisecond)
for user := range arn.StreamUsers() {
// Get osu info
if user.RefreshOsuInfo() == nil {
arn.PrettyPrint(user.Accounts.Osu)
// Fetch user again to prevent writing old data
updatedUser, _ := arn.GetUser(user.ID)
updatedUser.Accounts.Osu = user.Accounts.Osu
updatedUser.Save()
if user.Accounts.Osu.Nick == "" {
continue
}
// Fetch new info
err := user.RefreshOsuInfo()
if err != nil {
color.Red(err.Error())
continue
}
// Log it
arn.PrettyPrint(user.Accounts.Osu)
// Save in database
user.Save()
// Wait for rate limiter
<-ticker.C
}
color.Green("Finished.")
}