feat(cmd/joj3/conf): support effective time
This commit is contained in:
parent
575a3ae042
commit
b3663d8782
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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"`
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user