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 | 	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 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -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"` | ||||||
|  |  | ||||||
|  | @ -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 | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user