mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-08-02 17:59:14 +02:00
41 lines
1.3 KiB
Go
41 lines
1.3 KiB
Go
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/fetch/sport"
|
|
"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{})
|
|
})
|
|
|
|
// Every sunday at 2am fetch all sport events (5 segments - minute, hour, day, month, weekday) "0 2 * * 0"
|
|
scheduler.MustAdd("fetchEvents", "0 2 * * 0", func() {
|
|
sport.FetchAndUpdateSportEvents(app)
|
|
})
|
|
|
|
scheduler.Start()
|
|
return nil
|
|
})
|
|
|
|
}
|