From a77546d34bdb1914631452c4a9c2d9665d583d49 Mon Sep 17 00:00:00 2001 From: fcote Date: Sun, 19 Feb 2023 16:12:20 +0100 Subject: [PATCH] chore(scheduler): log jobs next run time on startup --- scheduler/main.go | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/scheduler/main.go b/scheduler/main.go index a2494f63..7f3b99ef 100644 --- a/scheduler/main.go +++ b/scheduler/main.go @@ -86,28 +86,40 @@ func main() { // Scheduler s := gocron.NewScheduler(location) + s.SingletonModeAll() if conf.Job.NewsSync.Enabled { - _, err := s.CronWithSeconds(conf.Job.NewsSync.Rule).Do(newsHandler.Handle) + j, err := s.CronWithSeconds(conf.Job.NewsSync.Rule).Do(newsHandler.Handle) if err != nil { logger.Fatal().Msgf("failed to initialize news sync job: %v", err) } - logger.Info().Msg("news sync job registered") + go logJobRegistered(j, "news sync") } if conf.Job.ForexSync.Enabled { - _, err := s.CronWithSeconds(conf.Job.ForexSync.Rule).Do(forexHandler.Handle) + j, err := s.CronWithSeconds(conf.Job.ForexSync.Rule).Do(forexHandler.Handle) if err != nil { logger.Fatal().Msgf("failed to initialize forex sync job: %v", err) } - logger.Info().Msg("forex sync job registered") + go logJobRegistered(j, "forex sync") } if conf.Job.FullSync.Enabled { - _, err := s.CronWithSeconds(conf.Job.FullSync.Rule).Do(fullSyncHandler.Handle) + j, err := s.CronWithSeconds(conf.Job.FullSync.Rule).Do(fullSyncHandler.Handle) if err != nil { logger.Fatal().Msgf("failed to initialize full sync job: %v", err) } - logger.Info().Msg("full sync job registered") + go logJobRegistered(j, "full sync") } s.StartBlocking() } + +func logJobRegistered(j *gocron.Job, name string) { + // waits for scheduler to start + <-time.After(1 * time.Second) + + glog.Get().Info().Msgf( + "job | registered %s | next run: %s", + name, + j.ScheduledTime().Format("2006-01-02 15:04:05"), + ) +}