package service import ( "github.com/pocketbase/pocketbase" "github.com/pocketbase/pocketbase/core" "github.com/pocketbase/pocketbase/tools/cron" "htwkalender/service/course" "htwkalender/service/feed" "htwkalender/service/functions/time" ) 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() { course.UpdateCourse(app) }) // Every sunday at 3am clean all courses (5 segments - minute, hour, day, month, weekday) "0 3 * * 0" scheduler.MustAdd("cleanFeeds", "0 3 * * 0", func() { // clean feeds older than 6 months feed.ClearFeeds(app.Dao(), 6, time.RealClock{}) }) scheduler.Start() return nil }) }