From 62fcd245f23ab0e12127c41e363db4538618d663 Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 11 Jun 2026 23:28:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=98=A0=E5=B0=84=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3=E7=9A=84?= =?UTF-8?q?=20task=5Ftype=20=E5=8F=82=E6=95=B0=E4=B8=BA=20Asynq=20?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=90=8D=E4=BB=A5=E8=A7=A3=E5=86=B3=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E8=BF=87=E6=BB=A4=E6=97=A0=E6=95=B0=E6=8D=AE=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/apps/admin/task/routers.go | 6 ++++++ internal/apps/admin/task/routers_test.go | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/internal/apps/admin/task/routers.go b/internal/apps/admin/task/routers.go index d9520a00..a77ce730 100644 --- a/internal/apps/admin/task/routers.go +++ b/internal/apps/admin/task/routers.go @@ -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())) diff --git a/internal/apps/admin/task/routers_test.go b/internal/apps/admin/task/routers_test.go index 8664c101..ae8cef78 100644 --- a/internal/apps/admin/task/routers_test.go +++ b/internal/apps/admin/task/routers_test.go @@ -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()