|
1 | | -from typing import Any, List |
| 1 | +from typing import Any, List, Dict |
2 | 2 | from submodules.model.business_objects import monitor as task_monitor |
3 | 3 | from controller.auth import kratos |
4 | 4 | from submodules.model.util import sql_alchemy_to_dict |
| 5 | +from submodules.s3 import controller as s3 |
5 | 6 |
|
6 | 7 |
|
7 | 8 | def monitor_all_tasks(page: int, limit: int) -> List[Any]: |
@@ -33,36 +34,85 @@ def cancel_upload_task(project_id: str = None, upload_task_id: str = None) -> No |
33 | 34 | task_monitor.set_upload_task_to_failed(project_id, upload_task_id, with_commit=True) |
34 | 35 |
|
35 | 36 |
|
36 | | -def cancel_weak_supervision(project_id: str = None, payload_id: str = None) -> None: |
37 | | - task_monitor.set_weak_supervision_to_failed( |
38 | | - project_id, payload_id, with_commit=True |
39 | | - ) |
| 37 | +def cancel_weak_supervision( |
| 38 | + task_info: Dict[str, Any], |
| 39 | +) -> None: |
| 40 | + project_id = task_info.get("projectId") |
| 41 | + payload_id = task_info.get("payloadId") |
| 42 | + if project_id and payload_id: |
| 43 | + task_monitor.set_weak_supervision_to_failed( |
| 44 | + project_id, payload_id, with_commit=True |
| 45 | + ) |
40 | 46 |
|
41 | 47 |
|
42 | 48 | def cancel_attribute_calculation( |
43 | | - project_id: str = None, attribute_id: str = None |
| 49 | + task_info: Dict[str, Any], |
44 | 50 | ) -> None: |
45 | | - task_monitor.set_attribute_calculation_to_failed( |
46 | | - project_id, attribute_id, with_commit=True |
47 | | - ) |
48 | 51 |
|
| 52 | + project_id = task_info.get("projectId") |
| 53 | + attribute_id = task_info.get("attributeId") |
| 54 | + if project_id and attribute_id: |
| 55 | + task_monitor.set_attribute_calculation_to_failed( |
| 56 | + project_id, attribute_id, with_commit=True |
| 57 | + ) |
49 | 58 |
|
50 | | -def cancel_embedding(project_id: str = None, embedding_id: str = None) -> None: |
51 | | - task_monitor.set_embedding_to_failed(project_id, embedding_id, with_commit=True) |
| 59 | + |
| 60 | +def cancel_embedding( |
| 61 | + task_info: Dict[str, Any], |
| 62 | +) -> None: |
| 63 | + project_id = task_info.get("projectId") |
| 64 | + embedding_id = task_info.get("embeddingId") |
| 65 | + if project_id and embedding_id: |
| 66 | + task_monitor.set_embedding_to_failed(project_id, embedding_id, with_commit=True) |
52 | 67 |
|
53 | 68 |
|
54 | 69 | def cancel_information_source_payload( |
55 | | - project_id: str = None, payload_id: str = None |
| 70 | + task_info: Dict[str, Any], |
56 | 71 | ) -> None: |
57 | | - task_monitor.set_information_source_payloads_to_failed( |
58 | | - project_id, payload_id, with_commit=True |
59 | | - ) |
| 72 | + project_id = task_info.get("projectId") |
| 73 | + payload_id = task_info.get("payloadId") |
| 74 | + if project_id and payload_id: |
| 75 | + task_monitor.set_information_source_payloads_to_failed( |
| 76 | + project_id, payload_id, with_commit=True |
| 77 | + ) |
60 | 78 |
|
61 | 79 |
|
62 | 80 | def cancel_record_tokenization_task( |
63 | | - project_id: str = None, |
64 | | - tokenization_task_id: str = None, |
| 81 | + task_info: Dict[str, Any], |
| 82 | +) -> None: |
| 83 | + project_id = task_info.get("projectId") |
| 84 | + tokenization_task_id = task_info.get("recordTokenizationTaskId") |
| 85 | + if project_id and tokenization_task_id: |
| 86 | + task_monitor.set_record_tokenization_task_to_failed( |
| 87 | + project_id, tokenization_task_id, with_commit=True |
| 88 | + ) |
| 89 | + |
| 90 | + |
| 91 | +def cancel_macro_execution_task( |
| 92 | + task_info: Dict[str, Any], |
65 | 93 | ) -> None: |
66 | | - task_monitor.set_record_tokenization_task_to_failed( |
67 | | - project_id, tokenization_task_id, with_commit=True |
| 94 | + |
| 95 | + macro_execution_id = task_info.get("executionId") |
| 96 | + macro_execution_group_id = task_info.get("groupExecutionId") |
| 97 | + |
| 98 | + task_monitor.set_macro_execution_task_to_failed( |
| 99 | + macro_execution_id, macro_execution_group_id, with_commit=True |
68 | 100 | ) |
| 101 | + |
| 102 | + |
| 103 | +def cancel_markdown_file_task( |
| 104 | + task_info: Dict[str, Any], |
| 105 | +) -> None: |
| 106 | + markdown_file_id = task_info.get("fileId") |
| 107 | + org_id = task_info.get("orgId") |
| 108 | + task_monitor.set_markdown_file_task_to_failed( |
| 109 | + markdown_file_id, org_id, with_commit=True |
| 110 | + ) |
| 111 | + |
| 112 | + |
| 113 | +def cancel_tmp_doc_retrieval_task( |
| 114 | + task_info: Dict[str, Any], |
| 115 | +) -> None: |
| 116 | + bucket = task_info.get("bucket") |
| 117 | + minio_path = task_info.get("minioPath") |
| 118 | + s3.delete_object(bucket, minio_path) |
0 commit comments