Skip to content

Commit f6e6f12

Browse files
Task master dashboard (#244)
* get all task simple * resolve name and org name * delete task from task queue db * model * Removed unused code * remove only running * submodules updated * Submodules merged --------- Co-authored-by: LennartSchmidtKern <[email protected]>
1 parent f23430b commit f6e6f12

File tree

3 files changed

+36
-30
lines changed

3 files changed

+36
-30
lines changed

controller/monitor/manager.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
from typing import Any, List
22
from submodules.model.business_objects import monitor as task_monitor
3+
from controller.auth import kratos
4+
from submodules.model.util import sql_alchemy_to_dict
35

46

5-
def monitor_all_tasks(project_id: str = None, only_running: bool = True) -> List[Any]:
6-
return task_monitor.get_all_tasks(project_id, only_running)
7+
def monitor_all_tasks(page: int, limit: int) -> List[Any]:
8+
tasks = task_monitor.get_all_tasks(page, limit)
9+
tasks_dict = sql_alchemy_to_dict(tasks)
10+
user_ids = {str(t["created_by"]) for t in tasks} # set comprehension
11+
name_lookup = {u_id: kratos.resolve_user_name_by_id(u_id) for u_id in user_ids}
12+
13+
for t in tasks_dict:
14+
created_by_first_last = name_lookup[str(t["created_by"])]
15+
t["created_by"] = (
16+
created_by_first_last["first"] + " " + created_by_first_last["last"]
17+
if created_by_first_last
18+
else "Unknown"
19+
)
20+
21+
# name comes from the join with organization
22+
t["organization_name"] = t["name"]
23+
del t["name"]
24+
25+
return tasks_dict
726

827

928
def cancel_all_running_tasks(project_id: str = None) -> None:

fast_api/routes/misc.py

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -87,36 +87,23 @@ def model_provider_download_model(
8787

8888

8989
@router.get("/all-tasks")
90-
def get_all_tasks(request: Request, only_running: bool):
90+
def get_all_tasks(request: Request, page: int = 1, limit: int = 100):
9191
auth.check_admin_access(request.state.info)
92-
tasks = controller_manager.monitor_all_tasks(only_running=only_running)
92+
tasks = controller_manager.monitor_all_tasks(page=page, limit=limit)
93+
return pack_json_result(tasks)
9394

94-
all_tasks = []
9595

96-
for task in tasks:
97-
started_at = None
98-
if task.started_at:
99-
started_at = task.started_at.isoformat()
100-
101-
finished_at = None
102-
if task.finished_at:
103-
finished_at = task.finished_at.isoformat()
104-
105-
all_tasks.append(
106-
{
107-
"projectId": str(task.project_id),
108-
"state": task.state,
109-
"taskType": task.task_type,
110-
"id": str(task.id),
111-
"createdBy": task.created_by,
112-
"organizationName": task.organization_name,
113-
"projectName": task.project_name,
114-
"startedAt": started_at,
115-
"finishedAt": finished_at,
116-
}
117-
)
118-
119-
return pack_json_result({"data": {"allTasks": all_tasks}})
96+
@router.delete(
97+
"/delete-from-task-queue-db",
98+
)
99+
def delete_from_task_queue_db(
100+
request: Request,
101+
task_id: str,
102+
org_id: str,
103+
):
104+
auth.check_admin_access(request.state.info)
105+
task_master_manager.delete_task(org_id, task_id)
106+
return SILENT_SUCCESS_RESPONSE
120107

121108

122109
@router.post("/cancel-task")

submodules/model

0 commit comments

Comments
 (0)