Skip to content

Commit 0522f9b

Browse files
more
1 parent 8ed9e2c commit 0522f9b

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

pioreactorui/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ def publish_to_experiment_log(msg: str | t.Any, experiment: str, task: str, leve
146146

147147
getattr(logger, level.lower())(msg)
148148

149-
topic = f"pioreactor/{get_leader_hostname()}/{experiment}/logs/ui/{level.lower()}"
150-
client.publish(topic, msg_to_JSON(msg, task, level))
149+
if am_I_leader():
150+
topic = f"pioreactor/{get_leader_hostname()}/{experiment}/logs/ui/{level.lower()}"
151+
client.publish(topic, msg_to_JSON(msg, task, level))
151152

152153

153154
def publish_to_error_log(msg, task: str) -> None:

pioreactorui/unit_api.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from werkzeug.utils import safe_join
2828

2929
from . import HOSTNAME
30+
from . import publish_to_error_log
3031
from . import query_temp_local_metadata_db
3132
from . import tasks
3233
from . import VERSION
@@ -547,15 +548,15 @@ def get_all_calibrations() -> ResponseReturnValue:
547548
with local_persistent_storage("active_calibrations") as cache:
548549
for file in calibration_dir.glob("*/*.yaml"):
549550
try:
551+
device = file.parent.name
550552
cal = yaml_decode(file.read_bytes())
551-
device = cal["device"]
552553
cal["is_active"] = cache.get(device) == cal["calibration_name"]
553554
if device in all_calibrations:
554555
all_calibrations[device].append(cal)
555556
else:
556557
all_calibrations[device] = [cal]
557558
except Exception as e:
558-
print(f"Error reading {file.stem}: {e}")
559+
publish_to_error_log(f"Error reading {file.stem}: {e}", "get_all_calibrations")
559560

560561
return attach_cache_control(jsonify(all_calibrations), max_age=10)
561562

@@ -572,11 +573,15 @@ def get_calibrations_by_device(device) -> ResponseReturnValue:
572573
with local_persistent_storage("active_calibrations") as c:
573574
for file in calibration_dir.glob("*.yaml"):
574575
try:
575-
cal = yaml_decode(file.read_bytes())
576+
cal = yaml_decode(
577+
file.read_bytes()
578+
) # dict, don't make Struct since we can't add fields to structs.
576579
cal["is_active"] = c.get(device) == cal["calibration_name"]
577580
calibrations.append(cal)
578581
except Exception as e:
579-
print(f"Error reading {file.stem}: {e}")
582+
publish_to_error_log(
583+
f"Error reading {file.stem}: {e}", "get_calibrations_by_device"
584+
)
580585

581586
return attach_cache_control(jsonify(calibrations), max_age=10)
582587

0 commit comments

Comments
 (0)