1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

chore: do not run expensive jobs initially but only scheduled

This commit is contained in:
Ferdinand Mütsch 2022-04-18 21:07:15 +02:00
parent 9d7688957f
commit ff7d595a86
3 changed files with 5 additions and 17 deletions

View File

@ -169,11 +169,9 @@ func main() {
miscService = services.NewMiscService(userService, summaryService, keyValueService) miscService = services.NewMiscService(userService, summaryService, keyValueService)
// Schedule background tasks // Schedule background tasks
if !config.QuickStart {
go aggregationService.Schedule() go aggregationService.Schedule()
go miscService.ScheduleCountTotalTime() go miscService.ScheduleCountTotalTime()
go reportService.Schedule() go reportService.Schedule()
}
routes.Init() routes.Init()

View File

@ -45,13 +45,8 @@ type AggregationJob struct {
// Schedule a job to (re-)generate summaries every day shortly after midnight // Schedule a job to (re-)generate summaries every day shortly after midnight
func (srv *AggregationService) Schedule() { 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 := 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() s.StartBlocking()
} }

View File

@ -38,13 +38,8 @@ type CountTotalTimeResult struct {
} }
func (srv *MiscService) ScheduleCountTotalTime() { 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 := gocron.NewScheduler(time.Local)
s.Every(1).Hour().Do(srv.runCountTotalTime) s.Every(1).Hour().WaitForSchedule().Do(srv.runCountTotalTime)
s.StartBlocking() s.StartBlocking()
} }