mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-13 17:47:51 +00:00
feat(server): integrate ip ban cron and refine updates
- Initialize and schedule IP ban maintenance tasks in server entry point - Perform initial IP ban sync to Redis on startup - Implement optional JSON unmarshalling to handle null `expires_at` in API - Add CIDR overlap validation when updating rule status to active
This commit is contained in:
@@ -235,6 +235,7 @@ func main() {
|
||||
authHandler := api.NewAuthHandler(db, rdb, adminService, masterService)
|
||||
ipBanService := service.NewIPBanService(db, rdb)
|
||||
ipBanHandler := api.NewIPBanHandler(ipBanService)
|
||||
ipBanManager := cron.NewIPBanManager(ipBanService)
|
||||
modelRegistryService := service.NewModelRegistryService(db, rdb, service.ModelRegistryConfig{
|
||||
Enabled: cfg.ModelRegistry.Enabled,
|
||||
RefreshEvery: time.Duration(cfg.ModelRegistry.RefreshSeconds) * time.Second,
|
||||
@@ -250,11 +251,17 @@ func main() {
|
||||
if err := syncService.SyncAll(db); err != nil {
|
||||
logger.Warn("initial sync warning", "err", err)
|
||||
}
|
||||
if err := ipBanService.SyncAllToRedis(context.Background()); err != nil {
|
||||
logger.Warn("initial IP ban sync warning", "err", err)
|
||||
}
|
||||
// Initial model registry refresh before scheduler starts
|
||||
if modelRegistryService.Enabled() {
|
||||
modelRegistryService.RunOnce(context.Background())
|
||||
sched.Every("model-registry-refresh", modelRegistryService.RefreshEvery(), modelRegistryService.RunOnce)
|
||||
}
|
||||
sched.Every("ip-ban-expire", time.Minute, ipBanManager.ExpireRunOnce)
|
||||
sched.Every("ip-ban-hit-sync", 5*time.Minute, ipBanManager.HitSyncRunOnce)
|
||||
sched.Every("ip-ban-full-sync", 5*time.Minute, ipBanManager.FullSyncRunOnce)
|
||||
sched.Start()
|
||||
|
||||
// 5. Setup Gin Router
|
||||
|
||||
Reference in New Issue
Block a user