Skip to content

Commit 2d2eb40

Browse files
committed
Removed database refresh instances from CLEM workflows, as they seem unneeded
1 parent d50f929 commit 2d2eb40

File tree

4 files changed

+10
-192
lines changed

4 files changed

+10
-192
lines changed

src/murfey/server/api/clem.py

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import re
4-
import time
54
import traceback
65
from ast import literal_eval
76
from importlib.metadata import EntryPoint # type hinting only
@@ -95,16 +94,16 @@ def validate_and_sanitise(
9594
if not str(full_path).startswith(str(base_path)):
9695
raise ValueError(f"{file} points to a directory that is not permitted")
9796

98-
# Check that it's a file, not a directory
99-
# Make a couple of attempts to rule out race condition
100-
attempts = 0
101-
while attempts < 50:
102-
if full_path.is_file() is True:
103-
break
104-
attempts += 1
105-
time.sleep(0.1)
106-
else:
107-
raise ValueError(f"{file} is not a file")
97+
# # Check that it's a file, not a directory
98+
# # Make a couple of attempts to rule out race condition
99+
# attempts = 0
100+
# while attempts < 50:
101+
# if full_path.is_file() is True:
102+
# break
103+
# attempts += 1
104+
# time.sleep(0.1)
105+
# else:
106+
# raise ValueError(f"{file} is not a file")
108107

109108
# Check that it is of a permitted file type
110109
if f"{full_path.suffix}" not in valid_file_types:
@@ -194,26 +193,6 @@ def get_db_entry(
194193
db.add(db_entry)
195194
db.commit()
196195

197-
# Make multiple attempts to refresh data in case of race condition
198-
attempts = 0
199-
while attempts < 50:
200-
try:
201-
db.refresh(db_entry)
202-
break
203-
except Exception:
204-
logger.warning(
205-
f"Attempt {attempts + 1} at refreshing database entry for "
206-
f"{sanitise(str(file_path if file_path else series_name))!r} failed: \n"
207-
f"{traceback.format_exc()}"
208-
)
209-
attempts += 1
210-
time.sleep(0.1)
211-
else:
212-
raise RuntimeError(
213-
"Maximum number of attempts reached while trying to refresh database "
214-
f"entry for {sanitise(str(file_path if file_path else series_name))!r}"
215-
)
216-
217196
except Exception:
218197
raise Exception
219198

src/murfey/workflows/clem/__init__.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import logging
44
import re
55
import time
6-
import traceback
76
from pathlib import Path
87
from typing import Optional, Type, Union
98

@@ -190,25 +189,6 @@ def get_db_entry(
190189
db.add(db_entry)
191190
db.commit()
192191

193-
# Make multiple attempts data retrieval attempts in case of race condition
194-
attempts = 0
195-
while attempts < 50:
196-
try:
197-
db.refresh(db_entry)
198-
break
199-
except Exception:
200-
logger.warning(
201-
f"Attempt {attempts + 1} at refreshing database entry for "
202-
f"{str(file_path if file_path else series_name)!r} failed: \n"
203-
f"{traceback.format_exc()}"
204-
)
205-
attempts += 1
206-
time.sleep(0.1)
207-
else:
208-
raise RuntimeError(
209-
"Maximum number of attempts reached while trying to refresh database "
210-
f"entry for {str(file_path if file_path else series_name)!r}"
211-
)
212192
except Exception:
213193
raise Exception
214194

src/murfey/workflows/clem/register_align_and_merge_results.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import json
44
import logging
5-
import time
65
import traceback
76
from ast import literal_eval
87
from pathlib import Path
@@ -95,26 +94,6 @@ def register_align_and_merge_result(
9594
murfey_db.add(clem_img_series)
9695
murfey_db.commit()
9796

98-
# Make multiple attempts to refresh data in case of race condition
99-
attempts = 0
100-
while attempts < 50:
101-
try:
102-
murfey_db.refresh(clem_img_series)
103-
break
104-
except Exception:
105-
logger.warning(
106-
f"Attempt {attempts + 1} at refreshing database entry for "
107-
f"{str(result.series_name)!r} failed: \n"
108-
f"{traceback.format_exc()}"
109-
)
110-
attempts += 1
111-
time.sleep(0.1)
112-
else:
113-
raise RuntimeError(
114-
"Maximum number of attempts reached while trying to refresh database "
115-
f"entry for {result.series_name!r}"
116-
)
117-
11897
logger.info(
11998
"Align-and-merge processing result registered for "
12099
f"{result.series_name!r} series"

src/murfey/workflows/clem/register_preprocessing_results.py

Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import json
1111
import logging
12-
import time
1312
import traceback
1413
from ast import literal_eval
1514
from pathlib import Path
@@ -121,75 +120,16 @@ def register_lif_preprocessing_result(
121120
murfey_db.add(clem_img_stk)
122121
murfey_db.commit()
123122

124-
# Make multiple attempts to refresh data in case of race condition
125-
attempts = 0
126-
while attempts < 50:
127-
try:
128-
murfey_db.refresh(clem_img_stk)
129-
break
130-
except Exception:
131-
logger.warning(
132-
f"Attempt {attempts + 1} at refreshing database entry for "
133-
f"{str(result.image_stack)!r} failed: \n"
134-
f"{traceback.format_exc()}"
135-
)
136-
attempts += 1
137-
time.sleep(0.1)
138-
else:
139-
raise RuntimeError(
140-
"Maximum number of attempts reached while trying to refresh database "
141-
f"entry for {str(result.image_stack)!r}"
142-
)
143-
144123
clem_img_series.associated_metadata = clem_metadata
145124
clem_img_series.parent_lif = clem_lif_file
146125
clem_img_series.number_of_members = result.number_of_members
147126
murfey_db.add(clem_img_series)
148127
murfey_db.commit()
149128

150-
# Make multiple attempts to refresh data in case of race condition
151-
attempts = 0
152-
while attempts < 50:
153-
try:
154-
murfey_db.refresh(clem_img_series)
155-
break
156-
except Exception:
157-
logger.warning(
158-
f"Attempt {attempts + 1} at refreshing database entry for "
159-
f"{str(result.series_name)!r} failed: \n"
160-
f"{traceback.format_exc()}"
161-
)
162-
attempts += 1
163-
time.sleep(0.1)
164-
else:
165-
raise RuntimeError(
166-
"Maximum number of attempts reached while trying to refresh database "
167-
f"entry for {str(result.series_name)!r}"
168-
)
169-
170129
clem_metadata.parent_lif = clem_lif_file
171130
murfey_db.add(clem_metadata)
172131
murfey_db.commit()
173132

174-
# Make multiple attempts to refresh data in case of race condition
175-
while attempts < 50:
176-
try:
177-
murfey_db.refresh(clem_metadata)
178-
break
179-
except Exception:
180-
logger.warning(
181-
f"Attempt {attempts + 1} at refreshing database entry for "
182-
f"{str(result.metadata)!r} failed: \n"
183-
f"{traceback.format_exc()}"
184-
)
185-
attempts += 1
186-
time.sleep(0.1)
187-
else:
188-
raise RuntimeError(
189-
"Maximum number of attempts reached while trying to refresh database "
190-
f"entry for {str(result.metadata)!r}"
191-
)
192-
193133
logger.info(
194134
f"LIF preprocessing results registered for {result.series_name!r} "
195135
f"{result.channel!r} image stack"
@@ -357,77 +297,17 @@ def register_tiff_preprocessing_result(
357297
murfey_db.add(clem_tiff_file)
358298
murfey_db.commit()
359299

360-
# Make multiple attempts to refresh data in case of race condition
361-
attempts = 0
362-
while attempts < 50:
363-
try:
364-
murfey_db.refresh(clem_tiff_file)
365-
break
366-
except Exception:
367-
logger.warning(
368-
f"Attempt {attempts + 1} at refreshing database entry for "
369-
f"{str(file)!r} failed: \n"
370-
f"{traceback.format_exc()}"
371-
)
372-
attempts += 1
373-
time.sleep(0.1)
374-
else:
375-
raise RuntimeError(
376-
"Maximum number of attempts reached while trying to refresh database "
377-
f"entry for {str(file)!r}"
378-
)
379-
380300
clem_img_stk.associated_metadata = clem_metadata
381301
clem_img_stk.parent_series = clem_img_series
382302
clem_img_stk.channel_name = result.channel
383303
murfey_db.add(clem_img_stk)
384304
murfey_db.commit()
385305

386-
# Make multiple attempts to refresh data in case of race condition
387-
attempts = 0
388-
while attempts < 50:
389-
try:
390-
murfey_db.refresh(clem_img_stk)
391-
break
392-
except Exception:
393-
logger.warning(
394-
f"Attempt {attempts + 1} at refreshing database entry for "
395-
f"{str(result.image_stack)!r} failed: \n"
396-
f"{traceback.format_exc()}"
397-
)
398-
attempts += 1
399-
time.sleep(0.1)
400-
else:
401-
raise RuntimeError(
402-
"Maximum number of attempts reached while trying to refresh database "
403-
f"entry for {str(result.image_stack)!r}"
404-
)
405-
406306
clem_img_series.associated_metadata = clem_metadata
407307
clem_img_series.number_of_members = result.number_of_members
408308
murfey_db.add(clem_img_series)
409309
murfey_db.commit()
410310

411-
# Make multiple attempts to refresh data in case of race condition
412-
attempts = 0
413-
while attempts < 50:
414-
try:
415-
murfey_db.refresh(clem_img_series)
416-
break
417-
except Exception:
418-
logger.warning(
419-
f"Attempt {attempts + 1} at refreshing database entry for "
420-
f"{str(result.series_name)!r} failed: \n"
421-
f"{traceback.format_exc()}"
422-
)
423-
attempts += 1
424-
time.sleep(0.1)
425-
else:
426-
raise RuntimeError(
427-
"Maximum number of attempts reached while trying to refresh database "
428-
f"entry for {str(result.series_name)!r}"
429-
)
430-
431311
logger.info(
432312
f"TIFF preprocessing results registered for {result.series_name!r} "
433313
f"{result.channel!r} image stack"

0 commit comments

Comments
 (0)