refactor: 添加 logger 模块并优化客户端实例清理逻辑

- 新增 logger 模块,统一使用 zap.SugaredLogger
- 将 config_api.go 中的 fmt.Printf 改为 logger.SugaredLogger.Errorf
- 客户端实例清理逻辑改为定时任务(每分钟执行)
- 清理条件改为 last_ping_at 超过 5 分钟
This commit is contained in:
2026-05-02 21:01:26 +08:00
parent 8957286bb5
commit 9a7679960c
5 changed files with 85 additions and 5 deletions
+2 -5
View File
@@ -1,8 +1,8 @@
package handler
import (
"fmt"
"kenaito-conf/server/internal/dao"
"kenaito-conf/server/internal/logger"
"kenaito-conf/server/internal/model"
"kenaito-conf/server/internal/service"
"net/http"
@@ -242,14 +242,11 @@ func (h *ConfigApiHandler) recordClientInstances(ip string, configIds []int, app
}
_, err := dao.Engine.Insert(&instance)
if err != nil {
fmt.Printf("[recordClientInstances] insert error: %v\n", err)
logger.SugaredLogger.Errorf("[recordClientInstances] insert error: %v", err)
continue
}
}
}
// cleanup records older than 5 minutes
fiveMinutesAgo := now.Add(-5 * time.Minute)
dao.Engine.Where("last_ping_at < ?", fiveMinutesAgo).Delete(&model.ClientInstance{})
}
// func (h *ConfigApiHandler) Ping(c *gin.Context) {