From b3663d87823141f5bd41766a74863fbb4737caf9 Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Wed, 12 Feb 2025 16:23:30 -0500 Subject: [PATCH] feat(cmd/joj3/conf): support effective time --- cmd/joj3/conf/conf.go | 11 ++++++++--- cmd/joj3/conf/model.go | 19 +++++++------------ cmd/joj3/main.go | 4 ++-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/cmd/joj3/conf/conf.go b/cmd/joj3/conf/conf.go index 8725c36..96491c1 100644 --- a/cmd/joj3/conf/conf.go +++ b/cmd/joj3/conf/conf.go @@ -173,10 +173,15 @@ func GetConfPath(confRoot, confName, fallbackConfName, msg, tag string) ( return } -func CheckExpire(conf *Conf) error { +func CheckValid(conf *Conf) error { + now := time.Now().Unix() + if conf.EffectiveUnixTimestamp > 0 && + conf.EffectiveUnixTimestamp > now { + return fmt.Errorf("config file not effective now: %d", now) + } if conf.ExpireUnixTimestamp > 0 && - conf.ExpireUnixTimestamp < time.Now().Unix() { - return fmt.Errorf("config file expired: %d", conf.ExpireUnixTimestamp) + conf.ExpireUnixTimestamp < now { + return fmt.Errorf("config file expired now: %d", now) } return nil } diff --git a/cmd/joj3/conf/model.go b/cmd/joj3/conf/model.go index 0815b6a..031fd14 100644 --- a/cmd/joj3/conf/model.go +++ b/cmd/joj3/conf/model.go @@ -20,19 +20,14 @@ type ConfStage struct { } } -type ConfGroup struct { - Name string - MaxCount int - TimePeriodHour int -} - type Conf struct { - Name string `default:"unknown"` - LogPath string `default:""` - ActorCsvPath string `default:""` - ExpireUnixTimestamp int64 `default:"-1"` - MaxTotalScore int `default:"-1"` - Stage struct { + Name string `default:"unknown"` + LogPath string `default:""` + ActorCsvPath string `default:""` + EffectiveUnixTimestamp int64 `default:"-1"` + ExpireUnixTimestamp int64 `default:"-1"` + MaxTotalScore int `default:"-1"` + Stage struct { SandboxExecServer string `default:"localhost:5051"` SandboxToken string `default:""` OutputPath string `default:"joj3_result.json"` diff --git a/cmd/joj3/main.go b/cmd/joj3/main.go index dce9402..eef373f 100644 --- a/cmd/joj3/main.go +++ b/cmd/joj3/main.go @@ -83,8 +83,8 @@ func mainImpl() (err error) { } slog.Info("conf info", "sha256", confSHA256, "modTime", confStat.ModTime(), "size", confStat.Size()) - if err := joj3Conf.CheckExpire(conf); err != nil { - slog.Error("conf check expire", "error", err) + if err := joj3Conf.CheckValid(conf); err != nil { + slog.Error("conf not valid now", "error", err) return err }