|
1 | 1 | from sqlalchemy import event |
2 | 2 | from datetime import datetime, timezone |
3 | 3 | from submodules.model.models import CognitionConversation, CognitionMessage |
4 | | -from submodules.model.session_wrapper import with_session |
5 | 4 | import traceback |
6 | 5 |
|
7 | 6 | from src.controller.admin_query_message_summary import ( |
8 | 7 | manager as admin_query_message_summary_manager, |
9 | 8 | ) |
| 9 | +from submodules.model.business_objects import general |
10 | 10 |
|
11 | 11 |
|
12 | 12 | @event.listens_for(CognitionConversation, "after_insert") |
13 | | -@with_session() |
14 | 13 | def after_insert(mapper, connection, conversation_entity: CognitionConversation): |
15 | 14 | try: |
| 15 | + session_token = general.get_ctx_token() |
16 | 16 | admin_query_message_summary_manager.log_conversation_summary( |
17 | 17 | conversation_entity, 1 |
18 | 18 | ) |
19 | 19 | except Exception: |
20 | | - print("Error in after_insert listener of CognitionConversation", flush=True) |
21 | 20 | print(traceback.format_exc(), flush=True) |
| 21 | + finally: |
| 22 | + general.remove_and_refresh_session(session_token) |
22 | 23 |
|
23 | 24 |
|
24 | 25 | @event.listens_for(CognitionMessage, "after_insert") |
25 | | -@with_session() |
26 | 26 | def after_insert(mapper, connection, message_entity: CognitionMessage): |
27 | 27 | try: |
| 28 | + session_token = general.get_ctx_token() |
28 | 29 | admin_query_message_summary_manager.log_message_summary(message_entity) |
29 | 30 | except Exception: |
30 | 31 | print("Error in after_insert listener of CognitionMessage", flush=True) |
31 | 32 | print(traceback.format_exc(), flush=True) |
| 33 | + finally: |
| 34 | + general.remove_and_refresh_session(session_token) |
0 commit comments