3636from util .notification import create_notification
3737from submodules .model .enums import NotificationType
3838from submodules .model .models import UploadTask
39- from util import daemon , notification
39+ from util import notification
40+ from submodules .model import daemon
4041from controller .transfer .cognition .minio_upload import handle_cognition_file_upload
4142
4243from controller .task_master import manager as task_master_manager
@@ -232,7 +233,7 @@ def put(self, request) -> PlainTextResponse:
232233 return PlainTextResponse ("Bad project id" , status_code = 400 )
233234 task_id = request .path_params ["task_id" ]
234235
235- daemon .run (
236+ daemon .run_without_db_token (
236237 cognition_import_wizard .prepare_and_finalize_setup ,
237238 cognition_project_id = cognition_project_id ,
238239 task_id = task_id ,
@@ -302,7 +303,7 @@ def init_file_import(task: UploadTask, project_id: str, is_global_update: bool)
302303 cognition_preparator .prepare_cognition_import (project_id , task )
303304 else :
304305 transfer_manager .import_records_from_file (project_id , task )
305- daemon .run (
306+ daemon .run_with_db_token (
306307 __recalculate_missing_attributes_and_embeddings ,
307308 project_id ,
308309 str (task .user_id ),
@@ -378,7 +379,6 @@ def __recalculate_missing_attributes_and_embeddings(
378379def __calculate_missing_attributes (project_id : str , user_id : str ) -> None :
379380 # wait a second to ensure that the process is started in the tokenization service
380381 time .sleep (5 )
381- ctx_token = general .get_ctx_token ()
382382 attributes_usable = attribute .get_all_ordered (
383383 project_id ,
384384 True ,
@@ -387,7 +387,6 @@ def __calculate_missing_attributes(project_id: str, user_id: str) -> None:
387387 ],
388388 )
389389 if len (attributes_usable ) == 0 :
390- general .remove_and_refresh_session (ctx_token , False )
391390 return
392391
393392 # stored as list so connection results do not affect
@@ -405,7 +404,7 @@ def __calculate_missing_attributes(project_id: str, user_id: str) -> None:
405404 i += 1
406405 if i >= 60 :
407406 i = 0
408- ctx_token = general . remove_and_refresh_session ( ctx_token , True )
407+ daemon . reset_session_token_in_thread ( )
409408 if tokenization .is_doc_bin_creation_running_or_queued (project_id ):
410409 time .sleep (2 )
411410 continue
@@ -420,7 +419,7 @@ def __calculate_missing_attributes(project_id: str, user_id: str) -> None:
420419 break
421420 if i >= 60 :
422421 i = 0
423- ctx_token = general . remove_and_refresh_session ( ctx_token , True )
422+ daemon . reset_session_token_in_thread ( )
424423
425424 current_att_id = attribute_ids [0 ]
426425 current_att = attribute .get (project_id , current_att_id )
@@ -468,4 +467,3 @@ def __calculate_missing_attributes(project_id: str, user_id: str) -> None:
468467 project_id = project_id ,
469468 message = "calculate_attribute:finished:all" ,
470469 )
471- general .remove_and_refresh_session (ctx_token , False )
0 commit comments