Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Go admin: update heartbeat (#20275)

Jin Hai5271bb0f37ab
diff --git a/internal/admin/handler.go b/internal/admin/handler.go
index ef81ecd76d..436130753f 100644
--- a/internal/admin/handler.go
+++ b/internal/admin/handler.go
@@ -1175,8 +1175,8 @@ func (h *Handler) Reports(c *gin.Context) {
}
// Handle the heartbeat
- errCode, message := h.service.HandleHeartbeat(&req)
- common.ErrorWithCode(c, errCode, message)
+ errCode, data, message := h.service.HandleHeartbeat(&req)
+ common.ResponseWithCodeData(c, errCode, data, message)
}
func (h *Handler) ListAllModels(c *gin.Context) {
diff --git a/internal/admin/service.go b/internal/admin/service.go
index a1c6a334d0..1f41c5fc48 100644
--- a/internal/admin/service.go
+++ b/internal/admin/service.go
@@ -1455,7 +1455,7 @@ func (s *Service) TestSandboxConnection(ctx context.Context, providerType string
var heartBeatCount int64 = 0
// HandleHeartbeat handle heartbeat
-func (s *Service) HandleHeartbeat(message *common.BaseMessage) (common.ErrorCode, string) {
+func (s *Service) HandleHeartbeat(message *common.BaseMessage) (common.ErrorCode, map[string]interface{}, string) {
heartBeatCount++
status := &common.BaseMessage{
diff --git a/internal/admin/service_ee.go b/internal/admin/service_ee.go
index b127d1ed5f..45ed04111d 100644
--- a/internal/admin/service_ee.go
+++ b/internal/admin/service_ee.go
@@ -30,8 +30,11 @@ import (
"gorm.io/gorm"
)
-func UpdateServer(serverName string, status *common.BaseMessage) (common.ErrorCode, string) {
- GlobalServerStore.UpdateServerInfo(serverName, status)
+func UpdateServer(serverName string, status *common.BaseMessage) (common.ErrorCode, map[string]interface{}, string) {
+ err := GlobalServerStore.UpdateServerInfo(serverName, status)
+ if err != nil {
+ return common.CodeErrorServerStatus, nil, err.Error()
+ }
return CheckLicense()
}
@@ -1241,8 +1244,12 @@ func (s *Service) RemoveIngestionTasksByCondition(ctx context.Context, tasks []s
return []map[string]interface{}{element}, nil
}
-func CheckLicense() (common.ErrorCode, string) {
- return common.CodeLicenseValid, ""
+func CheckClientStatus(serverName string, status *common.BaseMessage) error {
+ return nil
+}
+
+func CheckLicense() (common.ErrorCode, map[string]interface{}, string) {
+ return common.CodeLicenseValid, map[string]interface{}{}, ""
}
// DownloadSensitiveWords download sensitive words
diff --git a/internal/admin/state.go b/internal/admin/state.go
index 45c08397ae..1a5d0e41c2 100644
--- a/internal/admin/state.go
+++ b/internal/admin/state.go
@@ -36,29 +36,21 @@ var GlobalServerStore = &ServerStore{
}
// UpdateServerInfo updates or adds a server status
-func (s *ServerStore) UpdateServerInfo(serverName string, status *common.BaseMessage) {
+func (s *ServerStore) UpdateServerInfo(serverName string, status *common.BaseMessage) error {
- //switch serviceType {
- //case "meta_data":
- // return s.getMySQLStatus(name)
+ s.mu.Lock()
+ defer s.mu.Unlock()
switch status.ServerType {
case common.ServerTypeAPI:
- s.mu.Lock()
- defer s.mu.Unlock()
s.servers[serverName] = status
- return
case common.ServerTypeIngestion:
- s.mu.Lock()
- defer s.mu.Unlock()
s.servers[serverName] = status
- return
case common.ServerTypeFileSyncer:
- s.mu.Lock()
- defer s.mu.Unlock()
s.servers[serverName] = status
- return
}
+
+ return CheckClientStatus(serverName, status)
}
// GetServerInfo gets a single server status
diff --git a/internal/common/error_code.go b/internal/common/error_code.go
index 9c7a8d60cf..ec56f9ae67 100644
--- a/internal/common/error_code.go
+++ b/internal/common/error_code.go
@@ -44,6 +44,7 @@ const (
CodeLicenseNotFound ErrorCode = 325
CodeLicenseUnexpectedError ErrorCode = 326
CodeLicenseNotValidYet ErrorCode = 327
+ CodeErrorServerStatus ErrorCode = 330
CodeBadRequest ErrorCode = 400
CodeUnauthorized ErrorCode = 401
CodeForbidden ErrorCode = 403
diff --git a/internal/service/admin_client.go b/internal/service/admin_client.go
index 1a19413929..5d7ee839de 100644
--- a/internal/service/admin_client.go
+++ b/internal/service/admin_client.go
@@ -157,6 +157,13 @@ func (h *AdminClient) SendHeartbeat() error {
}
licenseStatusCode = responseCode
+ responseData := responseBody["data"]
+ err = h.UpdateClient(responseData)
+ if err != nil {
+ common.Error("fail to update client info", err)
+ return err
+ }
+
common.Debug("Heartbeat sent successfully",
zap.String("server_id", h.serverName),
zap.String("server_type", string(h.serverType)),
diff --git a/internal/service/admin_client_ee.go b/internal/service/admin_client_ee.go
index d2683d9bd8..f251ee0a1e 100644
--- a/internal/service/admin_client_ee.go
+++ b/internal/service/admin_client_ee.go
@@ -18,3 +18,5 @@ package service
func (h *AdminClient) InitHTTPClientEE() error {
return nil
}
+
+func (h *AdminClient) UpdateClient(clientInfo interface{}) error { return nil }