fix:#25 added tests and schedule updates

This commit is contained in:
Elmar Kresse
2024-04-22 16:11:13 +02:00
parent c8bcc3be94
commit 02a4360521
19 changed files with 731 additions and 203 deletions

View File

@@ -23,6 +23,7 @@ import (
"htwkalender/service/course"
"htwkalender/service/feed"
"htwkalender/service/fetch/sport"
v1 "htwkalender/service/fetch/v1"
v2 "htwkalender/service/fetch/v2"
"htwkalender/service/functions/time"
"log/slog"
@@ -34,10 +35,21 @@ func AddSchedules(app *pocketbase.PocketBase) {
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
scheduler := cron.New()
// Every hour update all courses (5 segments - minute, hour, day, month, weekday) "0 * * * *"
// Every three hours update all courses (5 segments - minute, hour, day, month, weekday) "0 */3 * * *"
// Every 10 minutes update all courses (5 segments - minute, hour, day, month, weekday) "*/10 * * * *"
scheduler.MustAdd("updateCourse", "0 */3 * * *", func() {
// !! IMPORTANT !! CRON is based on UTC time zone so in Germany it is UTC+2 in summer and UTC+1 in winter
// Every sunday at 10pm update all courses (5 segments - minute, hour, day, month, weekday) "0 22 * * 0"
scheduler.MustAdd("updateCourses", "0 22 * * 0", func() {
slog.Info("Started updating courses schedule")
groups, err := v1.FetchSeminarGroups(app)
if err != nil {
slog.Warn("Failed to fetch seminar groups: %v", err)
}
slog.Info("Successfully fetched " + strconv.FormatInt(int64(len(groups)), 10) + " seminar groups")
})
// Every day at 5am and 5pm update all courses (5 segments - minute, hour, day, month, weekday) "0 5,17 * * *"
// In Germany it is 7am and 7pm, syllabus gets updated twice a day at German 5:00 Uhr and 17:00 Uhr
scheduler.MustAdd("updateEventsByCourse", "0 5,17 * * *", func() {
slog.Info("Started updating courses schedule")
course.UpdateCourse(app)
})
@@ -60,7 +72,7 @@ func AddSchedules(app *pocketbase.PocketBase) {
})
//fetch all events for semester and delete from remote this should be done every sunday at 2am
scheduler.MustAdd("fetchEvents", "0 2 * * 0", func() {
scheduler.MustAdd("fetchEvents", "0 22 * * 6", func() {
savedEvents, err := v2.FetchAllEventsAndSave(app, time.RealClock{})
if err != nil {
slog.Error("Failed to fetch and save events: %v", err)