Clear expired appointments

This commit is contained in:
daru
2022-05-28 15:48:56 +02:00
parent 97f94e5e2f
commit f7c331c945

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"strconv"
"strings"
"time"
"github.com/gookit/color"
@@ -17,6 +18,34 @@ func Arbeiten() {
}
func Arbeit() {
// check appointments
appoints, err := ReadAppointments()
if err != nil {
if !strings.Contains(err.Error(), "not found") && err != nutsdb.ErrBucketEmpty {
color.Errorln(err.Error())
logOut.WriteError(err)
}
} else {
cleared := 0
for _, a := range appoints {
if a.Time.Before(time.Now()) {
// appointment expired
keyBytes := Int64AndDateToBytes(a.Anime, a.Time)
err = DbDelete(bucketAppoint, string(keyBytes))
if err != nil {
color.Errorln(err.Error())
logOut.WriteError(err)
} else {
cleared++
}
}
}
if cleared > 0 {
color.Infof("Cleared %d expired appointments\n", cleared)
logOut.WriteLine(fmt.Sprintf("♻️ Cleared %d expired appointments", cleared))
}
}
// refresh animelist of users
animesUsers, err := ReadAnimeUsers()
if err != nil {