Skip to content

feat: add customizable job state notification email templates - #137

Open
faureadr wants to merge 1 commit into
oar-team:masterfrom
faureadr:feat-custom-mail-templates
Open

feat: add customizable job state notification email templates#137
faureadr wants to merge 1 commit into
oar-team:masterfrom
faureadr:feat-custom-mail-templates

Conversation

@faureadr

@faureadr faureadr commented May 6, 2026

Copy link
Copy Markdown

Context

This commit introduces the ability for administrators to fully customize the notification emails sent to users upon various job state changes (Running, Terminated, Error, Suspended, Resuming) using simple text templates.

It features a robust, safe-fail mechanism: if a configured template is missing, malformed, or contains unknown formatting tags, OAR will gracefully fall back to its default hardcoded notification strings without interrupting the scheduler.

Changes

  • oar/lib/job_handling.py:
    • Implemented get_custom_notification_message with safe dictionary mapping and try/except blocks.
    • Modified set_job_state to inject custom templates into tools.notify_user, using the or operator for seamless fallbacks.
  • etc/oar/templates/mail/default/: Added 5 default rich-text template examples (mail_running.txt, mail_terminated.txt, mail_error.txt, mail_suspended.txt, mail_resuming.txt).
  • oar/tools/oar.conf.in: Added commented configuration variables (MAIL_TEMPLATE_RUNNING, MAIL_TEMPLATE_TERMINATED, etc.) to link the templates.
  • tests/lib/test_job_handling.py: Added test_get_custom_notification_message to validate template formatting, missing configs, and bad syntax handling using Pytest.
  • README.rst: Added a "Features" section to document this new capability.

This commit introduces the ability for administrators to fully customize the notification emails sent to users upon various job state changes (Running, Terminated, Error, Suspended, Resuming) using simple text templates.

It features a robust, safe-fail mechanism: if a configured template is missing, malformed, or contains unknown formatting tags, OAR will gracefully fall back to its default hardcoded notification strings without interrupting the scheduler.

Changes included:
- oar/lib/job_handling.py:
  * Implemented `get_custom_notification_message` with safe dictionary mapping and try/except blocks.
  * Modified `set_job_state` to inject custom templates into `tools.notify_user`, using the `or` operator for seamless fallbacks.

- etc/oar/templates/mail/default/: Added 5 default rich-text template examples (mail_running.txt, mail_terminated.txt, mail_error.txt, mail_suspended.txt, mail_resuming.txt).

- oar/tools/oar.conf.in: Added commented configuration variables (MAIL_TEMPLATE_RUNNING, MAIL_TEMPLATE_TERMINATED, etc.) to link the templates.

- tests/lib/test_job_handling.py: Added `test_get_custom_notification_message` to validate template formatting, missing configs, and bad syntax handling using Pytest.

- README.rst: Added a "Features" section to document this new capability.
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.

1 participant