eelib.utils.notification
Sends notifications for the status of simulations.
Module Contents
Classes
Abstract parent class for notifier objects. |
|
Class for sending notifications through email. Extends Notifier. |
|
Class for sending notifications through Webex App. Extends Notifier. |
|
Abstract parent class for a group of context manager classes. |
|
context manager class used to notify user of a simulation's status through email. |
|
context manager class used to notify user of a simulation's status through Webex. |
Attributes
- _logger
- class Notifier
Bases:
abc.ABCAbstract parent class for notifier objects.
- abstract send_message(sim_identifier: str, success: bool, message: str = None, recipient_email: str = None)
Abstract method for sending a message.
- Parameters:
sim_identifier (str) – an identifier for the simulation.
success (bool) – whether or not the simulation was successful.
message (str) – An additional message. Defaults to None.
recipient_email (str) – the recipient email. Defaults to None.
- construct_message(sim_identifier: str, success: bool, message: str = None)
Method to construct a message depending on success or failure of a simulation.
- Parameters:
sim_identifier (str) – an identifier for the simulation.
success (bool) – whether or not the simulation was successful.
message (str) – An additional message. Defaults to None.
- Returns:
the subject and content of the constructed message.
- Return type:
str, str
- class EmailNotifier(smtp_server: str = None, smtp_port: int = None, sender_email: str = None, sender_password: str = None)
Bases:
NotifierClass for sending notifications through email. Extends Notifier.
- send_message(sim_identifier: str, success: bool, message: str = None, recipient_email: str = None)
Sends email as a status update for a simulation.
- Parameters:
sim_identifier (str) – an identifier for the simulation.
success (bool) – whether or not the simulation was successful.
message (str) – An additional message. Defaults to None.
recipient_email (str) – the recipient email. Defaults to None.
- class WebexNotifier(api_url: str = None, access_token: str = None)
Bases:
NotifierClass for sending notifications through Webex App. Extends Notifier.
- send_message(sim_identifier: str, success: bool, message: str = None, recipient_email: str = None)
Sends webex message as a status update for a simulation.
- Parameters:
sim_identifier (str) – an identifier for the simulation.
success (bool) – whether or not the simulation was successful.
message (str) – An additional message. Defaults to None.
recipient_email (str) – the recipient’s email. Defaults to None.
- Returns:
json-encoded content of response or None.
- Return type:
Any
- class StatusMonitor(notifier, sim_identifier, recipient_email=None)
Bases:
abc.ABCAbstract parent class for a group of context manager classes.
Monitors the status of simulation and informs the user about success or failure. Use in the following format:
- with StatusMonitor(…):
execute_simulation()
- __enter__()
Called at the beginning of a with statement. Performs setup actions.
- __exit__(exc_type, exc_val, exc_tb)
Called at the end of a with statement. Performs teardown actions and handles exceptions.
- Parameters:
exc_type (Any) – The type of the exception if any.
exc_val (Any) – The value of the exception (e.g., the exception instance) if any.
exc_tb (Any) – A traceback object encapsulating the call stack at the point where the exception occurred.
- Returns:
returns False to propogate the exception.
- Return type:
bool
- class StatusMonitorEmail(sim_identifier, recipient_email=None, **kwargs)
Bases:
StatusMonitorcontext manager class used to notify user of a simulation’s status through email.
Extends StatusMonitor. Use in the following format:
- with StatusMonitor(…):
execute_simulation()
- class StatusMonitorWebex(sim_identifier, recipient_email=None, **kwargs)
Bases:
StatusMonitorcontext manager class used to notify user of a simulation’s status through Webex.
Extends StatusMonitor. Use in the following format:
- with StatusMonitor(…):
execute_simulation()