Skip to content

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

fix services stale clean (#21277)

Jin Hai572b00d546fa
diff --git a/internal/admin/service.go b/internal/admin/service.go
index ece3f5e173..47b2b19e06 100644
--- a/internal/admin/service.go
+++ b/internal/admin/service.go
@@ -793,7 +793,7 @@ func (s *Service) ListServices(ctx context.Context) ([]ServiceStatus, error) {
now := time.Now()
serverItem := newServiceStatus(string(serverStatus.ServerType), serverStatus.ServerName, serverStatus.Host, serverStatus.Port, "", serverStatus.Timestamp, "")
// the difference between now and serverStatus.Timestamp is less than 5 seconds, then the server is alive
- if now.Sub(serverStatus.Timestamp) < 45*time.Second {
+ if now.Sub(serverStatus.Timestamp) < 5*globalConfig.GetHeartbeatInterval() {
serverItem.Status = "alive"
} else {
serverItem.Status = "timeout"
diff --git a/internal/admin/service_ee.go b/internal/admin/service_ee.go
index 01edb94647..09e69d0294 100644
--- a/internal/admin/service_ee.go
+++ b/internal/admin/service_ee.go
@@ -21,12 +21,20 @@ import (
"errors"
"fmt"
"mime/multipart"
+ "ragflow/internal/server"
"ragflow/internal/common"
"ragflow/internal/dao"
"ragflow/internal/entity"
)
+func CheckServicePeriodically() {
+ globalConfig := server.GetConfig()
+
+ // By default, if no heartbeat is received for 10 times, then the server is considered as stale
+ GlobalServerStore.CleanupStaleStatuses(globalConfig.GetHeartbeatInterval() * 10)
+}
+
func UpdateServer(serverName string, status *common.BaseMessage) (common.ErrorCode, map[string]interface{}, string) {
err := GlobalServerStore.UpdateServerInfo(serverName, status)
if err != nil {
diff --git a/internal/common/error_code.go b/internal/common/error_code.go
index ec56f9ae67..ce632bd88e 100644
--- a/internal/common/error_code.go
+++ b/internal/common/error_code.go
@@ -56,6 +56,7 @@ const (
var errorMessages = map[ErrorCode]string{
CodeSuccess: "Success",
+ CodeLackResources: "Lack resources",
CodeNotEffective: "Not effective",
CodeExceptionError: "System exception",
CodeArgumentError: "Invalid argument",
@@ -76,12 +77,15 @@ var errorMessages = map[ErrorCode]string{
CodeLicenseTimeRollback: "License time rollback detected",
CodeLicenseNotFound: "License not found",
CodeLicenseUnexpectedError: "Unexpected license error",
+ CodeLicenseNotValidYet: "License not valid yet",
+ CodeErrorServerStatus: "Error server status",
CodeBadRequest: "Bad request",
CodeUnauthorized: "Unauthorized",
CodeForbidden: "Forbidden",
CodeNotFound: "Resource not found",
CodeConflict: "Resource conflict",
CodeServerError: "Internal server error",
+ CodeNotImplemented: "Not implemented",
}
func (e ErrorCode) Message() string {
diff --git a/internal/server/admin/server.go b/internal/server/admin/server.go
index 0cea6c636e..d8be1e00cd 100644
--- a/internal/server/admin/server.go
+++ b/internal/server/admin/server.go
@@ -23,6 +23,7 @@ import (
"errors"
"fmt"
"net/http"
+ "ragflow/internal/utility"
"time"
"github.com/gin-gonic/gin"
@@ -101,6 +102,10 @@ func Run(ctx context.Context, serverName string, args *bootstrap.ServerArgs) err
// Set log level
bootstrap.SetLogger(serverName, args)
+ validator := utility.NewScheduledTask("Admin validator", globalConfig.GetHeartbeatInterval(), adminapi.CheckServicePeriodically)
+ validator.Start()
+ defer validator.Stop()
+
// Start HTTP server in a goroutine
go func() {
common.Info(fmt.Sprintf("Starting RAGFlow admin HTTP server on port: %d", adminConfig.HTTPPort))