mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-01 05:23:47 +08:00
Add scheduled tasks (#13470)
### What problem does this PR solve? 1. RAGFlow server will send heartbeat periodically. 2. This PR will including: - Scheduled task - API server message sending - Admin server API to receive the message. ### Type of change - [x] New Feature (non-breaking change which adds functionality) --------- Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -19,10 +19,12 @@ package admin
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"ragflow/internal/common"
|
||||
"ragflow/internal/server"
|
||||
"ragflow/internal/service"
|
||||
"ragflow/internal/utility"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -111,7 +113,7 @@ func (h *Handler) Login(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
user, code, err := h.userService.LoginByEmail(&req)
|
||||
user, code, err := h.userService.LoginByEmail(&req, true)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"code": code,
|
||||
@@ -135,8 +137,9 @@ func (h *Handler) Login(c *gin.Context) {
|
||||
c.Header("Access-Control-Expose-Headers", "Authorization")
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 0,
|
||||
"message": "Login successful",
|
||||
"code": common.CodeSuccess,
|
||||
"message": "Welcome back!",
|
||||
"data": user,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -943,3 +946,31 @@ func (h *Handler) HandleNoRoute(c *gin.Context) {
|
||||
Message: "The requested resource was not found",
|
||||
})
|
||||
}
|
||||
|
||||
// Reports handle heartbeat reports from servers
|
||||
func (h *Handler) Reports(c *gin.Context) {
|
||||
var req common.BaseMessage
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
errorResponse(c, "Invalid request body: "+err.Error(), 400)
|
||||
return
|
||||
}
|
||||
|
||||
// Set default timestamp if not provided
|
||||
if req.Timestamp.IsZero() {
|
||||
req.Timestamp = time.Now()
|
||||
}
|
||||
|
||||
// Only process heartbeat messages for now
|
||||
if req.MessageType != common.MessageHeartbeat {
|
||||
errorResponse(c, "Unsupported report type: "+string(req.MessageType), 400)
|
||||
return
|
||||
}
|
||||
|
||||
// Handle the heartbeat
|
||||
if err := h.service.HandleHeartbeat(&req); err != nil {
|
||||
errorResponse(c, "Failed to process heartbeat: "+err.Error(), 500)
|
||||
return
|
||||
}
|
||||
|
||||
successNoData(c, "Heartbeat received successfully")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user