Skip to content

Commit 06b8c4e

Browse files
Macro external data endpoint (#162)
* perf: retrieve macro execution conversation * perf: SQL select conversation ID only * perf: add all() method to enums.MacroTypes * perf: add task_queue wait for exec group id
1 parent 72972c3 commit 06b8c4e

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

business_objects/task_queue.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,23 @@ def get_waiting_by_information_source(project_id: str, source_id: str) -> TaskQu
8383
)
8484

8585

86+
def get_waiting_by_macro_group_execution_ids(
87+
project_id: str, source_ids: List[str]
88+
) -> TaskQueue:
89+
source_ids = prevent_sql_injection(source_ids, isinstance(source_ids, list))
90+
return (
91+
session.query(TaskQueue)
92+
.filter(
93+
TaskQueue.task_type == enums.TaskType.RUN_COGNITION_MACRO.value,
94+
text(
95+
f"task_info->>'group_execution_id' IN ({','.join(map(repr, source_ids))})"
96+
),
97+
text(f"task_info->>'project_id' = '{project_id}'"),
98+
)
99+
.first()
100+
)
101+
102+
86103
def get_by_tokenization(project_id: str) -> TaskQueue:
87104
# could have multiple tokenization tasks in queue
88105
# if active => something is running else it's queued

cognition_objects/macro.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,22 @@ def get_macro_execution_data_for_message_queue(
626626
return []
627627

628628

629+
def get_macro_execution_group_conversation_id(group_id: str):
630+
group_id = prevent_sql_injection(group_id, isinstance(group_id, str))
631+
query = f"""
632+
SELECT
633+
c.id
634+
FROM
635+
cognition.conversation c
636+
WHERE
637+
c.scope_dict->>'group_execution_id' = '{group_id}';
638+
"""
639+
result = general.execute_first(query)
640+
if result and result[0]:
641+
return result[0]
642+
return None
643+
644+
629645
def delete_by_exec_groups(
630646
macro_id: str,
631647
group_ids: List[str],

enums.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,12 @@ class MacroType(Enum):
755755
DOCUMENT_MESSAGE_QUEUE = "DOCUMENT_MESSAGE_QUEUE"
756756
FOLDER_MESSAGE_QUEUE = "FOLDER_MESSAGE_QUEUE"
757757

758+
def all():
759+
return [
760+
MacroType.DOCUMENT_MESSAGE_QUEUE.value,
761+
MacroType.FOLDER_MESSAGE_QUEUE.value,
762+
]
763+
758764

759765
# currently only one option, but could be extended in the future
760766
class MacroNodeContentType(Enum):

0 commit comments

Comments
 (0)