fix(flomni): don't let a disabled scilog crash a tomo scan or pause the queue
tomo_scan() called bec.messaging.scilog directly with no guard, so a session without scilog enabled raised RuntimeError from inside tomo_queue_execute() -- marking the job "incomplete" and pausing the whole queue over a logging side effect unrelated to whether the tomogram succeeded. Adds _scilog_write(), mirroring the enabled-check already used for the PDF report entry, and routes the three unguarded call sites (tomo_scan, scilog_last_ptycho_scans, the alignment-scan entry) through it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -2251,9 +2251,7 @@ class Flomni(
|
||||
f"Alignment scan numbers: {scan_list_str}\n"
|
||||
)
|
||||
print(scilog_content)
|
||||
bec.messaging.scilog.new().add_text(scilog_content.replace("\n", "<br>")).add_tags(
|
||||
"alignmentscan"
|
||||
).send()
|
||||
self._scilog_write(scilog_content, "alignmentscan")
|
||||
|
||||
def write_alignment_scan_numbers(self, first_scan):
|
||||
import os
|
||||
@@ -2737,9 +2735,7 @@ class Flomni(
|
||||
for line in timing_lines[3:]:
|
||||
print(line)
|
||||
timing_content = "\n".join(timing_lines)
|
||||
bec.messaging.scilog.new().add_text(timing_content.replace("\n", "<br>")).add_tags(
|
||||
"tomoscan"
|
||||
).send()
|
||||
self._scilog_write(timing_content, "tomoscan")
|
||||
|
||||
def tomo_scan_resume(self) -> None:
|
||||
"""Resume a tomo_scan() that crashed or was interrupted, picking up
|
||||
@@ -2802,6 +2798,29 @@ class Flomni(
|
||||
return f"{m}m {s:02d}s"
|
||||
return f"{s}s"
|
||||
|
||||
def _scilog_write(self, text: str, tags: str | list) -> bool:
|
||||
"""Write a text entry to scilog, tolerating scilog being disabled or
|
||||
unreachable. This is documentation of a scan, not part of the scan
|
||||
itself -- it must never fail a caller (in particular a tomo_queue
|
||||
job, which would otherwise be marked "incomplete" and pause the
|
||||
whole queue over a logging side effect that has nothing to do with
|
||||
whether the tomogram actually succeeded).
|
||||
|
||||
Returns True if the entry was sent, False if it was skipped/failed
|
||||
(already logged as a warning either way -- callers that don't care
|
||||
about the outcome can ignore the return value).
|
||||
"""
|
||||
scilog = getattr(bec.messaging, "scilog", None)
|
||||
if scilog is None or not getattr(scilog, "_enabled", False):
|
||||
logger.warning("scilog is not enabled; skipping scilog entry.")
|
||||
return False
|
||||
try:
|
||||
scilog.new().add_text(text.replace("\n", "<br>")).add_tags(tags).send()
|
||||
return True
|
||||
except Exception as exc:
|
||||
logger.warning(f"Failed to write to scilog: {exc}")
|
||||
return False
|
||||
|
||||
def _print_progress(self):
|
||||
# --- compute and store estimated remaining time -----------------------
|
||||
start_str = self.progress.get("tomo_start_time")
|
||||
@@ -3138,10 +3157,7 @@ class Flomni(
|
||||
content = "\n".join(lines)
|
||||
print(content)
|
||||
|
||||
bec = builtins.__dict__.get("bec")
|
||||
bec.messaging.scilog.new().add_text(content.replace("\n", "<br>")).add_tags(
|
||||
"tomoscan"
|
||||
).send()
|
||||
self._scilog_write(content, "tomoscan")
|
||||
|
||||
def _write_tomo_scan_number(self, scan_number: int, angle: float, subtomo_number: int) -> None:
|
||||
tomo_scan_numbers_file = os.path.expanduser("~/data/raw/logs/tomography_scannumbers.txt")
|
||||
|
||||
Reference in New Issue
Block a user