Skip to content

Commit

Permalink
run on start if api disabled and cron enabled (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
bakito authored Dec 23, 2024
1 parent 9a7c617 commit 523e068
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions pkg/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down

0 comments on commit 523e068

Please sign in to comment.