Skip to content

Email the requester when a UI-launched run finishes - #6869

Open
ayoubdiourin7 wants to merge 13 commits into
mozilla:masterfrom
ayoubdiourin7:notify-run-completed
Open

ayoubdiourin7 wants to merge 13 commits into
mozilla:masterfrom
ayoubdiourin7:notify-run-completed

Conversation

@ayoubdiourin7

Copy link
Copy Markdown
Contributor

Fixes #6866

@ayoubdiourin7
ayoubdiourin7 marked this pull request as ready for review September 17, 2026 19:02
@ayoubdiourin7
ayoubdiourin7 requested a review from a team as a code owner September 17, 2026 19:02
run.agent,
)
await pubsub.publish_run_completed(str(run.run_id), run.agent, run.status)
await notifications.notify_requester(run)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in the internal API that receives the "run completed" events.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ui_base_url: str = "http://localhost:3000"
sendgrid_api_key: str = ""
notification_sender: str = ""
notification_override_email: str = ""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need notification_override_email?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s for testing. It redirects emails to a test inbox so we can verify that notifications work correctly.

Comment thread services/hackbot-api/app/notifications.py Outdated
Comment thread services/hackbot-api/app/notifications.py Outdated

def build_message(run: Run) -> tuple[str, str]:
"""Compose the subject and Markdown body of the notice for ``run``."""
outcome = run.status.replace("_", " ")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would mention the first part of the run ID, similar to the UI. If there is a bug id, I would mention it here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated in839d796

Comment thread services/hackbot-api/app/notifications.py Outdated
recipient = _recipient(run)
subject, body = build_message(run)
try:
status_code = await asyncio.to_thread(_send_sync, recipient, subject, body)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a native way to send async?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked, and SendGrid’s Python SDK doesn’t support native async sending.

Comment on lines +75 to +76
if not run.requested_by:
return False

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should file an issue to have a proper why to identify it was triggered by the UI (that issue would be blocked by #6724). That issue should be referenced here.

Comment thread services/hackbot-api/app/notifications.py Outdated
Comment thread services/hackbot-api/app/config.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow Hackbot UI users to opt-in to receiving an email when the job has completed

2 participants