Skip to content

Commit

Permalink
Add query param to avoid resending night log emails
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Oct 28, 2024
1 parent 71cf634 commit 02c1195
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lvmapi/routers/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions src/lvmapi/tools/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 02c1195

Please sign in to comment.