package internal import ( "context" "time" "github.com/go-co-op/gocron" ) var ( scheduler *gocron.Scheduler ) func StartSchedule(ctx context.Context) error { logger.Info("Starting schedule") cronExpression := GetEnvWithDefault("SCHEDULE_CRON", "0 0 * * *") scheduler = gocron.NewScheduler(time.Local) job, err := scheduler.Cron(cronExpression).Do(Backup, ctx) if err != nil { return err } logger.Debug("Next scheduled backup", "time", job.NextRun()) scheduler.StartBlocking() return nil } func StopSchedule() { if scheduler != nil { scheduler.StopBlockingChan() } }