From 6731b8b1e079639c4d41414f22edb93ca5fde257 Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Mon, 15 May 2023 15:38:18 +0200 Subject: [PATCH] Add clean functionality to archive manager --- tools/archive-manager/main.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/tools/archive-manager/main.go b/tools/archive-manager/main.go index 07cc4c1..988bb78 100644 --- a/tools/archive-manager/main.go +++ b/tools/archive-manager/main.go @@ -9,12 +9,28 @@ import ( "flag" "fmt" "os" + "time" "github.com/ClusterCockpit/cc-backend/internal/config" "github.com/ClusterCockpit/cc-backend/pkg/archive" "github.com/ClusterCockpit/cc-backend/pkg/log" ) +func parseDate(in string) int64 { + const shortForm = "2006-Jan-02" + loc, _ := time.LoadLocation("Local") + if in != "" { + t, err := time.ParseInLocation(shortForm, in, loc) + if err != nil { + fmt.Printf("date parse error %v", err) + os.Exit(0) + } + return t.Unix() + } + + return 0 +} + func main() { var srcPath, flagConfigFile, flagLogLevel, flagRemoveCluster, flagRemoveAfter, flagRemoveBefore string var flagLogDateTime, flagValidate bool @@ -24,8 +40,8 @@ func main() { flag.StringVar(&flagLogLevel, "loglevel", "warn", "Sets the logging level: `[debug,info,warn (default),err,fatal,crit]`") flag.StringVar(&flagConfigFile, "config", "./config.json", "Specify alternative path to `config.json`") flag.StringVar(&flagRemoveCluster, "remove-cluster", "", "Remove cluster from archive and database") - flag.StringVar(&flagRemoveBefore, "remove-before", "", "Remove all jobs with start time before date") - flag.StringVar(&flagRemoveAfter, "remove-after", "", "Remove all jobs with start time after date") + flag.StringVar(&flagRemoveBefore, "remove-before", "", "Remove all jobs with start time before date (Format: 2006-Jan-04)") + flag.StringVar(&flagRemoveAfter, "remove-after", "", "Remove all jobs with start time after date (Format: 2006-Jan-04)") flag.BoolVar(&flagValidate, "validate", false, "Set this flag to validate a job archive against the json schema") flag.Parse() @@ -47,5 +63,10 @@ func main() { os.Exit(0) } + if flagRemoveBefore != "" || flagRemoveAfter != "" { + ar.Clean(parseDate(flagRemoveBefore), parseDate(flagRemoveAfter)) + os.Exit(0) + } + ar.Info() }