From 02c1195d70ea4e455c53eaa2e3e5fd17e36e3b9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20S=C3=A1nchez-Gallego?= Date: Mon, 28 Oct 2024 08:38:26 +0000 Subject: [PATCH] Add query param to avoid resending night log emails --- src/lvmapi/routers/logs.py | 6 +++++- src/lvmapi/tools/logs.py | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lvmapi/routers/logs.py b/src/lvmapi/routers/logs.py index 755ba50..b48820d 100644 --- a/src/lvmapi/routers/logs.py +++ b/src/lvmapi/routers/logs.py @@ -222,11 +222,15 @@ async def route_get_night_logs_mjd_email( int, Path(description="The MJD for which to retrieve night log."), ], + only_if_not_sent: Annotated[ + bool, + Query(description="Only send the email if it has not been already been sent."), + ] = False, ): """Emails the night log.""" mjd = mjd if mjd > 0 else get_sjd("LCO") - data = await email_night_log(mjd) + data = await email_night_log(mjd, only_if_not_sent=only_if_not_sent) return data diff --git a/src/lvmapi/tools/logs.py b/src/lvmapi/tools/logs.py index 892232b..edef13d 100644 --- a/src/lvmapi/tools/logs.py +++ b/src/lvmapi/tools/logs.py @@ -547,6 +547,7 @@ async def email_night_log( sjd: int | None = None, update_database: bool = True, send_slack_notification: bool = True, + only_if_not_sent: bool = False, ): """Emails the night log for an SJD.""" @@ -581,6 +582,9 @@ async def email_night_log( compact_lamps=True, ) + if data["sent"] and only_if_not_sent: + raise RuntimeError(f"Night log for MJD {sjd} has already been sent.") + observers = data["observers"] or "Overwatcher" date = Time(sjd - 1, format="mjd").datetime.strftime("%A, %B %-d, %Y") lvmweb_url = config["night_logs.lvmweb_url"] + str(sjd)