mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-01 05:23:47 +08:00
Go: Admin list ingestion tasks (#14695)
### What problem does this PR solve? ``` RAGFlow(admin)> list tasks; +-------------+------------------+----------------------------------+-------------+-----------+----------------------------------+----------+----------------------+-------------+-----------+---------+ | chunk_count | digest | document_id | duration | from_page | id | priority | progress | retry_count | task_type | to_page | +-------------+------------------+----------------------------------+-------------+-----------+----------------------------------+----------+----------------------+-------------+-----------+---------+ | 16 | 8a0016a0dc3cbdbb | f6aa38bb4ad111f1ba6338a74640adcc | 1511.156966 | 0 | f91e4f104ad111f1aaaf38a74640adcc | 0 | 1 | 1 | | 12 | +-------------+------------------+----------------------------------+-------------+-----------+----------------------------------+----------+----------------------+-------------+-----------+---------+ ``` ### 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:
@@ -208,6 +208,15 @@ func (h *Handler) AuthCheck(c *gin.Context) {
|
||||
successNoData(c, "Admin is authorized")
|
||||
}
|
||||
|
||||
// ListTasks handle list tasks
|
||||
func (h *Handler) ListTasks(c *gin.Context) {
|
||||
tasks, err := h.service.ListTasks()
|
||||
if err != nil {
|
||||
errorResponse(c, err.Error(), 500)
|
||||
}
|
||||
success(c, tasks, "Get all tasks")
|
||||
}
|
||||
|
||||
// ListUsers handle list users
|
||||
func (h *Handler) ListUsers(c *gin.Context) {
|
||||
users, err := h.service.ListUsers()
|
||||
|
||||
@@ -55,6 +55,9 @@ func (r *Router) Setup(engine *gin.Engine) {
|
||||
// Auth
|
||||
protected.GET("/auth", r.handler.AuthCheck)
|
||||
|
||||
// Tasks
|
||||
protected.GET("/tasks", r.handler.ListTasks)
|
||||
|
||||
// User management
|
||||
protected.GET("/users", r.handler.ListUsers)
|
||||
protected.POST("/users", r.handler.CreateUser)
|
||||
|
||||
@@ -34,6 +34,7 @@ import (
|
||||
"ragflow/internal/utility"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
@@ -100,6 +101,37 @@ func (s *Service) Logout(user interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListTasks
|
||||
func (s *Service) ListTasks() ([]map[string]interface{}, error) {
|
||||
|
||||
tasks, err := s.taskDAO.GetAllTasks()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result []map[string]interface{}
|
||||
for _, task := range tasks {
|
||||
// task.ChunkIDs is a string, delimiter is space, count the word count
|
||||
ChunkCount := strings.Count(*task.ChunkIDs, " ")
|
||||
result = append(result, map[string]interface{}{
|
||||
"id": task.ID,
|
||||
"task_type": task.TaskType,
|
||||
"document_id": task.DocID,
|
||||
"chunk_count": ChunkCount,
|
||||
"from_page": task.FromPage,
|
||||
"to_page": task.ToPage,
|
||||
"priority": task.Priority,
|
||||
"duration": task.ProcessDuration,
|
||||
"progress": task.Progress,
|
||||
//"message": *task.ProgressMsg,
|
||||
"retry_count": task.RetryCount,
|
||||
"digest": task.Digest,
|
||||
})
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetUserByToken get user by access token
|
||||
func (s *Service) GetUserByToken(token string) (*entity.User, error) {
|
||||
user, err := s.userDAO.GetByAccessToken(token)
|
||||
|
||||
Reference in New Issue
Block a user