From 9fd9ffbb3dc0be88f0d860cb126b705d24a9e126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferdinand=20M=C3=BCtsch?= Date: Mon, 12 Apr 2021 23:36:22 +0200 Subject: [PATCH] fix: missing summary aggregation after days without heartbeats (see #168) --- services/aggregation.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/services/aggregation.go b/services/aggregation.go index 6f71b63..7eba357 100644 --- a/services/aggregation.go +++ b/services/aggregation.go @@ -38,6 +38,11 @@ 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(nil); 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, map[string]bool{}) s.StartBlocking() @@ -144,7 +149,7 @@ func generateUserJobs(userId string, from time.Time, jobs chan<- *AggregationJob var to time.Time // Go to next day of either user's first heartbeat or latest aggregation - from.Add(-1 * time.Second) + from = from.Add(-1 * time.Second) from = time.Date( from.Year(), from.Month(),