docker-s3-backup/internal/schedule.go

30 lines
492 B
Go

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