mml.core.scripts.notifier
Module to send notifications of MML execution via various media to the user.
- class BaseNotifier[source]
Bases:
ABC- __init__(on_start: bool = False, on_end: bool = False, on_failure: bool = True)[source]
The notifier base class provides utilities to send messages for mml events.
- Parameters:
on_start – emit message on mml start
on_end – emit message on (successful) mml end
on_failure – emit message on mml failure (except keyboard interrupt / user caused SIGTERM signal)
- abstract emit_message(text: str) None[source]
Abstract method that must implement the message delivery mechanism for inherited classes.
- Parameters:
text – the text to be sent
- Returns:
- get_message_header() str[source]
Helper to return uniform message header for all kinds of messages.
- Returns:
A header string to be used by notifiers.
- static is_master() bool[source]
Checks if the current process is the master process - used e.g. in Multi-GPU settings to prevent sending multiple messages from each node / process.
- Returns:
- notify_on_end(return_value: float | None) None[source]
The notification wrapper function to be called from outside in case MML end.
- Parameters:
return_value (Optional[float]) – the return value of the scheduler
- Returns:
- notify_on_failure(error: BaseException) None[source]
The notification wrapper function to be called from outside in case MML fails.
- Parameters:
error (Exception) – an error that caused MML to fail
- Returns:
- notify_on_start() None[source]
The notification wrapper function to be called from outside in case MML starts.
- Returns:
- static search_overrides() str[source]
For enriching messages the used overrides to call MML are tried to be read from the hydra config. If reading is not successful the returned string is a message describing the failed attempt to read
- Returns:
if successful the string that can be used to reproduce the MML call, otherwise a failure description
- class DummyNotifier[source]
Bases:
BaseNotifier
- class EMailNotifier[source]
Bases:
BaseNotifier- emit_message(text: str) None[source]
A function to send a simple email notification.
All email settings are read from the mml.env environment variables (thus they have to be set beforehand): MML_SMTP_SERVER MML_SMTP_SERVER_PORT MML_SENDER_EMAIL MML_RECEIVER_EMAIL MML_MAIL_PASSWORD=NO_PASSWORD (set to NO_PASSWORD if there is no password necessary, otherwise set password)
- Parameters:
text – message to be sent via email
- Returns:
- class SlackNotifier[source]
Bases:
BaseNotifier- emit_message(text: str) None[source]
A function to send a simple slack notification. All slack settings are read from the mml.env environment variables (thus they have to be set beforehand).
A slack app has to be created via the web interface and added to the workspace. Here are some example settings:
display_information: name: MML Monitoring description: Alerts from the mml monitoring system. background_color: "#8B0000" features: bot_user: display_name: MML Monitoring Alert always_online: true oauth_config: scopes: bot: - incoming-webhook settings: org_deploy_enabled: false socket_mode_enabled: false token_rotation_enabled: falseGenerate the webhook and store it inside the mml.env under “MML_SLACK_WEBHOOK_URL” to enable the notifier.
- Parameters:
text – message to be sent via slack
- Returns: