diff --git a/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py b/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py
index b11349a..96c9fff 100644
--- a/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py
+++ b/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py
@@ -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", "
")).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", "
")).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", "
")).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", "
")).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")