fix: 映射后台任务查询接口的 task_type 参数为 Asynq 任务名以解决类型过滤无数据问题

This commit is contained in:
ryan
2026-06-11 23:28:50 +08:00
parent 01b80ac376
commit 62fcd245f2
2 changed files with 24 additions and 1 deletions
+6
View File
@@ -117,6 +117,12 @@ func ListTaskExecutions(c *gin.Context) {
return
}
if req.TaskType != "" {
if meta := task.GetTaskMeta(req.TaskType); meta != nil {
req.TaskType = meta.AsynqTask
}
}
executions, total, err := model.ListTaskExecutions(c.Request.Context(), req)
if err != nil {
c.JSON(http.StatusInternalServerError, util.Err(err.Error()))
+18 -1
View File
@@ -270,7 +270,7 @@ func TestListTaskExecutions(t *testing.T) {
assert.Equal(t, float64(1), data["total"])
})
t.Run("filter by task_type", func(t *testing.T) {
t.Run("filter by task_type (asynq task name)", func(t *testing.T) {
req, _ := http.NewRequest("GET", "/api/v1/admin/tasks/executions?task_type=upload:cleanup_unused", nil)
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
@@ -287,6 +287,23 @@ func TestListTaskExecutions(t *testing.T) {
assert.Equal(t, float64(3), data["total"])
})
t.Run("filter by task_type (management task type)", func(t *testing.T) {
req, _ := http.NewRequest("GET", "/api/v1/admin/tasks/executions?task_type=cleanup_unused_uploads", nil)
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
assert.Equal(t, http.StatusOK, w.Code)
var resp util.ResponseAny
json.Unmarshal(w.Body.Bytes(), &resp)
dataBytes, _ := json.Marshal(resp.Data)
var data map[string]interface{}
json.Unmarshal(dataBytes, &data)
assert.Equal(t, float64(3), data["total"])
})
t.Run("pagination", func(t *testing.T) {
req, _ := http.NewRequest("GET", "/api/v1/admin/tasks/executions?page=1&page_size=2", nil)
w := httptest.NewRecorder()