feat(cmd/joj3/conf): support effective time
All checks were successful
submodules sync / sync (push) Successful in 41s
build / build (push) Successful in 1m35s
build / trigger-build-image (push) Successful in 7s

This commit is contained in:
张泊明518370910136 2025-02-12 16:23:30 -05:00
parent 575a3ae042
commit b3663d8782
GPG Key ID: D47306D7062CDA9D
3 changed files with 17 additions and 17 deletions

View File

@ -173,10 +173,15 @@ func GetConfPath(confRoot, confName, fallbackConfName, msg, tag string) (
return 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 && if conf.ExpireUnixTimestamp > 0 &&
conf.ExpireUnixTimestamp < time.Now().Unix() { conf.ExpireUnixTimestamp < now {
return fmt.Errorf("config file expired: %d", conf.ExpireUnixTimestamp) return fmt.Errorf("config file expired now: %d", now)
} }
return nil return nil
} }

View File

@ -20,19 +20,14 @@ type ConfStage struct {
} }
} }
type ConfGroup struct {
Name string
MaxCount int
TimePeriodHour int
}
type Conf struct { type Conf struct {
Name string `default:"unknown"` Name string `default:"unknown"`
LogPath string `default:""` LogPath string `default:""`
ActorCsvPath string `default:""` ActorCsvPath string `default:""`
ExpireUnixTimestamp int64 `default:"-1"` EffectiveUnixTimestamp int64 `default:"-1"`
MaxTotalScore int `default:"-1"` ExpireUnixTimestamp int64 `default:"-1"`
Stage struct { MaxTotalScore int `default:"-1"`
Stage struct {
SandboxExecServer string `default:"localhost:5051"` SandboxExecServer string `default:"localhost:5051"`
SandboxToken string `default:""` SandboxToken string `default:""`
OutputPath string `default:"joj3_result.json"` OutputPath string `default:"joj3_result.json"`

View File

@ -83,8 +83,8 @@ func mainImpl() (err error) {
} }
slog.Info("conf info", "sha256", confSHA256, "modTime", confStat.ModTime(), slog.Info("conf info", "sha256", confSHA256, "modTime", confStat.ModTime(),
"size", confStat.Size()) "size", confStat.Size())
if err := joj3Conf.CheckExpire(conf); err != nil { if err := joj3Conf.CheckValid(conf); err != nil {
slog.Error("conf check expire", "error", err) slog.Error("conf not valid now", "error", err)
return err return err
} }