From ff7d595a86fb324f3210e80a055b1ffca8b1bd7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferdinand=20M=C3=BCtsch?= Date: Mon, 18 Apr 2022 21:07:15 +0200 Subject: [PATCH] chore: do not run expensive jobs initially but only scheduled --- main.go | 8 +++----- services/aggregation.go | 7 +------ services/misc.go | 7 +------ 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/main.go b/main.go index c2a62c3..804e015 100644 --- a/main.go +++ b/main.go @@ -169,11 +169,9 @@ func main() { miscService = services.NewMiscService(userService, summaryService, keyValueService) // Schedule background tasks - if !config.QuickStart { - go aggregationService.Schedule() - go miscService.ScheduleCountTotalTime() - go reportService.Schedule() - } + go aggregationService.Schedule() + go miscService.ScheduleCountTotalTime() + go reportService.Schedule() routes.Init() diff --git a/services/aggregation.go b/services/aggregation.go index 6310ef9..f11653a 100644 --- a/services/aggregation.go +++ b/services/aggregation.go @@ -45,13 +45,8 @@ type AggregationJob struct { // Schedule a job to (re-)generate summaries every day shortly after midnight func (srv *AggregationService) Schedule() { - // Run once initially - if err := srv.Run(datastructure.NewSet[string]()); err != nil { - logbuch.Fatal("failed to run AggregationJob: %v", err) - } - s := gocron.NewScheduler(time.Local) - s.Every(1).Day().At(srv.config.App.AggregationTime).Do(srv.Run, datastructure.NewSet[string]()) + s.Every(1).Day().At(srv.config.App.AggregationTime).WaitForSchedule().Do(srv.Run, datastructure.NewSet[string]()) s.StartBlocking() } diff --git a/services/misc.go b/services/misc.go index e1b03d5..f493209 100644 --- a/services/misc.go +++ b/services/misc.go @@ -38,13 +38,8 @@ type CountTotalTimeResult struct { } func (srv *MiscService) ScheduleCountTotalTime() { - // Run once initially - if err := srv.runCountTotalTime(); err != nil { - logbuch.Fatal("failed to run CountTotalTimeJob: %v", err) - } - s := gocron.NewScheduler(time.Local) - s.Every(1).Hour().Do(srv.runCountTotalTime) + s.Every(1).Hour().WaitForSchedule().Do(srv.runCountTotalTime) s.StartBlocking() }