Skip to content

Commit ba46115

Browse files
Session Improvements Async (#305)
* testing session * session debug * asyn middleware * await fix * add default * model * model * bracket * model * Submodule update --------- Co-authored-by: JWittmeyer <[email protected]>
1 parent 5988b4c commit ba46115

File tree

13 files changed

+41
-41
lines changed

13 files changed

+41
-41
lines changed

api/transfer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def __calculate_missing_attributes(project_id: str, user_id: str) -> None:
218218
i += 1
219219
if i >= 60:
220220
i = 0
221-
general.remove_and_refresh_session(request_new=True)
221+
general.remove_and_refresh_session(None, True)
222222
if tokenization.is_doc_bin_creation_running_or_queued(project_id):
223223
time.sleep(2)
224224
continue
@@ -233,7 +233,7 @@ def __calculate_missing_attributes(project_id: str, user_id: str) -> None:
233233
break
234234
if i >= 60:
235235
i = 0
236-
general.remove_and_refresh_session(request_new=True)
236+
general.remove_and_refresh_session(None, True)
237237

238238
current_att_id = attribute_ids[0]
239239
current_att = attribute.get(project_id, current_att_id)

conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222

2323
@pytest.fixture(scope="session", autouse=True)
2424
def database_session() -> Iterator[None]:
25-
session_token = general.get_ctx_token()
25+
general.get_ctx_token()
2626
yield
27-
general.remove_and_refresh_session(session_token)
27+
general.remove_and_refresh_session()
2828

2929

3030
@pytest.fixture(scope="session")

controller/attribute/manager.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def __add_running_id(
215215
attribute_name: str,
216216
for_retokenization: bool = True,
217217
):
218-
session_token = general.get_ctx_token()
218+
general.get_ctx_token()
219219
attribute.add_running_id(
220220
project_id, attribute_name, for_retokenization, with_commit=True
221221
)
@@ -231,7 +231,7 @@ def __add_running_id(
231231
"project_id": str(project_id),
232232
},
233233
)
234-
general.remove_and_refresh_session(session_token)
234+
general.remove_and_refresh_session()
235235

236236

237237
def calculate_user_attribute_missing_records(
@@ -301,7 +301,7 @@ def __calculate_user_attribute_missing_records(
301301
attribute_id: str,
302302
include_rats: bool,
303303
) -> None:
304-
session_token = general.get_ctx_token()
304+
general.get_ctx_token()
305305

306306
all_records_count = record.count(project_id)
307307
count_delta = record.count_missing_delta(project_id, attribute_id)
@@ -329,7 +329,7 @@ def __calculate_user_attribute_missing_records(
329329
attribute_id=attribute_id,
330330
log="Attribute calculation failed",
331331
)
332-
general.remove_and_refresh_session(session_token)
332+
general.remove_and_refresh_session()
333333
return
334334

335335
util.add_log_to_attribute_logs(
@@ -354,7 +354,7 @@ def __calculate_user_attribute_missing_records(
354354
attribute_id=attribute_id,
355355
log="Writing to the database failed.",
356356
)
357-
general.remove_and_refresh_session(session_token)
357+
general.remove_and_refresh_session()
358358
return
359359
util.add_log_to_attribute_logs(project_id, attribute_id, "Finished writing.")
360360

@@ -394,7 +394,7 @@ def __calculate_user_attribute_missing_records(
394394
attribute_id=attribute_id,
395395
log="Writing to the database failed.",
396396
)
397-
general.remove_and_refresh_session(session_token)
397+
general.remove_and_refresh_session()
398398
return
399399

400400
else:
@@ -410,7 +410,7 @@ def __calculate_user_attribute_missing_records(
410410
attribute_id=attribute_id,
411411
log="Writing to the database failed.",
412412
)
413-
general.remove_and_refresh_session(session_token)
413+
general.remove_and_refresh_session()
414414
return
415415
util.set_progress(project_id, attribute_item, 1.0)
416416
attribute.update(
@@ -424,7 +424,7 @@ def __calculate_user_attribute_missing_records(
424424
notification.send_organization_update(
425425
project_id, f"calculate_attribute:finished:{attribute_id}"
426426
)
427-
general.remove_and_refresh_session(session_token)
427+
general.remove_and_refresh_session()
428428

429429

430430
def __notify_attribute_calculation_failed(

controller/attribute/util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ def read_container_logs_thread(
512512
attribute_id: str,
513513
docker_container: Any,
514514
) -> None:
515-
ctx_token = general.get_ctx_token()
515+
general.get_ctx_token()
516516
# needs to be refetched since it is not thread safe
517517
attribute_item = attribute.get(project_id, attribute_id)
518518
previous_progress = -1
@@ -522,7 +522,7 @@ def read_container_logs_thread(
522522
time.sleep(1)
523523
c += 1
524524
if c > 100:
525-
ctx_token = general.remove_and_refresh_session(ctx_token, True)
525+
general.remove_and_refresh_session(None, True)
526526
attribute_item = attribute.get(project_id, attribute_id)
527527
if not attribute_item:
528528
break
@@ -564,7 +564,7 @@ def read_container_logs_thread(
564564
continue
565565
previous_progress = last_entry
566566
set_progress(project_id, attribute_item, last_entry * 0.8 + 0.05)
567-
general.remove_and_refresh_session(ctx_token)
567+
general.remove_and_refresh_session()
568568

569569

570570
def set_progress(

controller/payload/payload_scheduler.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def prepare_and_run_execution_pipeline(
9797
in_thread: bool = False,
9898
) -> None:
9999
if in_thread:
100-
ctx_token = general.get_ctx_token()
100+
general.get_ctx_token()
101101
try:
102102
add_file_name, input_data = prepare_input_data_for_payload(
103103
information_source_item
@@ -123,7 +123,7 @@ def prepare_and_run_execution_pipeline(
123123
)
124124
finally:
125125
if in_thread:
126-
general.reset_ctx_token(ctx_token, True)
126+
general.reset_ctx_token(None, True)
127127

128128
def prepare_input_data_for_payload(
129129
information_source_item: InformationSource,
@@ -452,7 +452,7 @@ def read_container_logs_thread(
452452
payload_id: str,
453453
docker_container: Any,
454454
):
455-
ctx_token = general.get_ctx_token()
455+
general.get_ctx_token()
456456
# needs to be refetched since it is not thread safe
457457
information_source_payload = information_source.get_payload(project_id, payload_id)
458458
previous_progress = -1
@@ -462,7 +462,7 @@ def read_container_logs_thread(
462462
time.sleep(1)
463463
c += 1
464464
if c > 100:
465-
ctx_token = general.remove_and_refresh_session(ctx_token, True)
465+
general.remove_and_refresh_session(None, True)
466466
information_source_payload = information_source.get_payload(
467467
project_id, payload_id
468468
)
@@ -504,7 +504,7 @@ def read_container_logs_thread(
504504
set_payload_progress(
505505
project_id, information_source_payload, last_entry, factor=0.8
506506
)
507-
general.remove_and_refresh_session(ctx_token)
507+
general.remove_and_refresh_session()
508508

509509

510510
def get_inference_dir() -> str:

controller/project/manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def check_in_deletion_projects() -> None:
354354
def __check_in_deletion_projects() -> None:
355355
# wait for startup to finish
356356
time.sleep(2)
357-
ctx_token = general.get_ctx_token()
357+
general.get_ctx_token()
358358
to_be_deleted = []
359359
orgs = organization.get_all()
360360
for org_item in orgs:
@@ -364,4 +364,4 @@ def __check_in_deletion_projects() -> None:
364364
to_be_deleted.append(str(project_item.id))
365365
for project_id in to_be_deleted:
366366
delete_project(project_id)
367-
general.remove_and_refresh_session(ctx_token)
367+
general.remove_and_refresh_session()

controller/record/manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ def delete_all_records(project_id: str) -> None:
134134

135135

136136
def __reupload_embeddings(project_id: str) -> None:
137-
ctx_token = general.get_ctx_token()
137+
general.get_ctx_token()
138138
embeddings = embedding.get_finished_embeddings(project_id)
139139
for e in embeddings:
140140
embedding_manager.request_tensor_upload(project_id, str(e.id))
141-
general.remove_and_refresh_session(ctx_token)
141+
general.remove_and_refresh_session()
142142

143143

144144
def get_unique_values_by_attributes(project_id: str) -> Dict[str, List[str]]:

controller/record_label_association/manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ def create_manual_classification_label(
156156
def __check_label_duplication_classification_and_react(
157157
project_id: str, record_id: str, user_id: str, label_ids: List[str]
158158
):
159-
ctx_token = general.get_ctx_token()
159+
general.get_ctx_token()
160160
if check_label_duplication_classification(
161161
project_id, record_id, user_id, label_ids
162162
):
163163
notification.send_organization_update(project_id, f"rla_deleted:{record_id}")
164-
general.remove_and_refresh_session(ctx_token)
164+
general.remove_and_refresh_session()
165165

166166

167167
def __update_label_payloads_for_neural_search(project_id: str, record_id: str):

controller/transfer/project_transfer_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -921,12 +921,12 @@ def __post_processing_import_threaded(
921921
user_id: str,
922922
) -> None:
923923
time.sleep(5)
924-
ctx_token = general.get_ctx_token()
924+
general.get_ctx_token()
925925
c = 1
926926
while True:
927927
c += 1
928928
if c > 12:
929-
ctx_token = general.remove_and_refresh_session(ctx_token, True)
929+
general.remove_and_refresh_session(None, True)
930930
c = 1
931931
if task_queue.get_by_tokenization(project_id):
932932
logger.info(f"Waiting for tokenization of project {project_id}")
@@ -945,7 +945,7 @@ def __post_processing_import_threaded(
945945
embedding_manager.request_tensor_upload(
946946
project_id, str(embedding_ids[old_id])
947947
)
948-
general.remove_and_refresh_session(ctx_token)
948+
general.remove_and_refresh_session()
949949

950950

951951
def get_project_export_dump(

controller/weak_supervision/manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def execution_pipeline(
5858
overwrite_default_precision: Optional[float] = None,
5959
overwrite_weak_supervision: Optional[Dict[str, float]] = None,
6060
):
61-
ctx_token = general.get_ctx_token()
61+
general.get_ctx_token()
6262
try:
6363
labeling_tasks = labeling_task.get_labeling_tasks_by_selected_sources(
6464
project_id
@@ -106,7 +106,7 @@ def execution_pipeline(
106106
)
107107
raise e
108108
finally:
109-
general.reset_ctx_token(ctx_token)
109+
general.reset_ctx_token()
110110

111111
daemon.run_without_db_token(
112112
execution_pipeline,

0 commit comments

Comments
 (0)