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()