From 523e068195e038f3f8dd78e850827567b7e94be8 Mon Sep 17 00:00:00 2001 From: Marc Brugger Date: Mon, 23 Dec 2024 08:16:19 +0100 Subject: [PATCH] run on start if api disabled and cron enabled (#474) --- pkg/sync/sync.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/pkg/sync/sync.go b/pkg/sync/sync.go index c39ccb4e..b28bea63 100644 --- a/pkg/sync/sync.go +++ b/pkg/sync/sync.go @@ -66,16 +66,12 @@ func Sync(cfg *types.Config) error { if cfg.API.Port != 0 { w.cron.Start() } else { + runOnStartAsync(cfg, w) w.cron.Run() } } if cfg.API.Port != 0 { - if cfg.RunOnStart { - go func() { - l.Info("Running sync on startup") - w.sync() - }() - } + runOnStartAsync(cfg, w) w.listenAndServe() } else if cfg.RunOnStart { l.Info("Running sync on startup") @@ -85,6 +81,15 @@ func Sync(cfg *types.Config) error { return nil } +func runOnStartAsync(cfg *types.Config, w *worker) { + if cfg.RunOnStart { + go func() { + l.Info("Running sync on startup") + w.sync() + }() + } +} + type worker struct { cfg *types.Config running bool