Skip to content

Commit 5e47efe

Browse files
committed
Added logic to trigger warning email within first 500 messages received; optimised logic for subsequent emails
1 parent d95ed64 commit 5e47efe

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/murfey/workflows/spa/picking.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -393,20 +393,30 @@ def _check_notifications(message: dict, murfey_db: Session) -> None:
393393
len(param_values) >= 25
394394
and sum(p.within_bounds for p in param_values) / len(param_values)
395395
< 0.25
396-
and not param.notification_active
397396
):
397+
# If notifications disabled, enable them now
398+
trigger = False
398399
if not param.notification_active:
400+
# Use a variable to trigger the notification for the first
401+
# time within the first 500 messages received
402+
if param_values[-1].index < 500:
403+
logger.debug(
404+
f"First abnormal instance of parameter {param.name!r} detected"
405+
)
406+
trigger = True
399407
param.notification_active = True
400408

401-
if param.num_instances_since_triggered >= 500:
402-
logger.debug(
403-
f"Parameter {param.name!r} has consistently exceeded normal "
404-
"operating thresholds"
405-
)
409+
if param.num_instances_since_triggered >= 500 or trigger:
410+
if not trigger:
411+
logger.debug(
412+
f"Parameter {param.name!r} has exceeded normal operating thresholds"
413+
)
406414
failures.append(param.name)
407415
param.num_instances_since_triggered = 0
408416
else:
409-
if param.notification_active:
417+
# Only reset to False if there are more than 500 instances
418+
# to stop multiple triggers within the first 500
419+
if param.notification_active and param_values[-1].index > 500:
410420
param.notification_active = False
411421

412422
# Delete oldest value

0 commit comments

Comments
 (0)