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

This commit is contained in:
Jonas Kaninda
2024-10-20 06:52:36 +02:00
parent 3f7d28ea49
commit 2c6336e84a
9 changed files with 41 additions and 7 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
@@ -187,3 +189,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
}