From e6918187568dbd01842d8d1d2c808ce16a894239 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 21 Apr 2024 13:54:28 +0200 Subject: Adding upstream version 18.2.2. Signed-off-by: Daniel Baumann --- src/pybind/mgr/dashboard/controllers/task.py | 46 ++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/pybind/mgr/dashboard/controllers/task.py (limited to 'src/pybind/mgr/dashboard/controllers/task.py') diff --git a/src/pybind/mgr/dashboard/controllers/task.py b/src/pybind/mgr/dashboard/controllers/task.py new file mode 100644 index 000000000..d5fbc34a7 --- /dev/null +++ b/src/pybind/mgr/dashboard/controllers/task.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- + +from ..services import progress +from ..tools import TaskManager +from . import APIDoc, APIRouter, EndpointDoc, RESTController + +TASK_SCHEMA = { + "executing_tasks": (str, "ongoing executing tasks"), + "finished_tasks": ([{ + "name": (str, "finished tasks name"), + "metadata": ({ + "pool": (int, "") + }, ""), + "begin_time": (str, "Task begin time"), + "end_time": (str, "Task end time"), + "duration": (int, ""), + "progress": (int, "Progress of tasks"), + "success": (bool, ""), + "ret_value": (bool, ""), + "exception": (bool, "") + }], "") +} + + +@APIRouter('/task') +@APIDoc("Task Management API", "Task") +class Task(RESTController): + @EndpointDoc("Display Tasks", + parameters={ + 'name': (str, 'Task Name'), + }, + responses={200: TASK_SCHEMA}) + def list(self, name=None): + executing_t, finished_t = TaskManager.list_serializable(name) + + e, f = progress.get_progress_tasks() + executing_t.extend(e) + finished_t.extend(f) + + executing_t.sort(key=lambda t: t['begin_time'], reverse=True) + finished_t.sort(key=lambda t: t['end_time'], reverse=True) + + return { + 'executing_tasks': executing_t, + 'finished_tasks': finished_t + } -- cgit v1.2.3