chore: add backup prune, replace period flag by BACKUP_RETENTION_DAYS environment variable

This commit is contained in:
Jonas Kaninda
2024-10-20 06:01:30 +02:00
parent 6d50862538
commit f7514ccf33
10 changed files with 44 additions and 10 deletions

View File

@@ -8,11 +8,13 @@ package utils
import (
"fmt"
"github.com/robfig/cron/v3"
"github.com/spf13/cobra"
"io"
"io/fs"
"os"
"strconv"
"time"
)
// FileExists checks if the file does exist
@@ -188,3 +190,26 @@ func EnvWithDefault(envName string, defaultValue string) string {
}
return value
}
// IsValidCronExpression verify cronExpression and returns boolean
func IsValidCronExpression(cronExpr string) bool {
// Parse the cron expression
_, err := cron.ParseStandard(cronExpr)
return err == nil
}
// CronNextTime returns cronExpression next time
func CronNextTime(cronExpr string) time.Time {
// Parse the cron expression
schedule, err := cron.ParseStandard(cronExpr)
if err != nil {
Error("Error parsing cron expression:", err)
return time.Time{}
}
// Get the current time
now := time.Now()
// Get the next scheduled time
next := schedule.Next(now)
//Info("The next scheduled time is: %v\n", next)
return next
}