From 998e71236c80bc1beca06a39f11067a6e556e73f Mon Sep 17 00:00:00 2001 From: Vishal Gupta Date: Fri, 27 Dec 2024 07:52:52 +0000 Subject: [PATCH] Update import notification settings --- import-automation/executor/app/configs.py | 2 ++ .../executor/app/executor/import_executor.py | 16 ++++++---------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/import-automation/executor/app/configs.py b/import-automation/executor/app/configs.py index 0df79f0c66..85fe5cf3e2 100644 --- a/import-automation/executor/app/configs.py +++ b/import-automation/executor/app/configs.py @@ -118,6 +118,8 @@ class ExecutorConfig: email_account: str = '' # The corresponding password, app password, or access token. email_token: str = '' + # Disbale email alert notifications. + disable_email_notifications: bool = False # Maximum time a blocking call to the importer to # perform an import can take in seconds. importer_import_timeout: float = 20 * 60 diff --git a/import-automation/executor/app/executor/import_executor.py b/import-automation/executor/app/executor/import_executor.py index bf49bfeaa4..e35f8be559 100644 --- a/import-automation/executor/app/executor/import_executor.py +++ b/import-automation/executor/app/executor/import_executor.py @@ -285,6 +285,8 @@ def _import_one( import_name = import_spec['import_name'] absolute_import_name = import_target.get_absolute_import_name( relative_import_dir, import_name) + curator_emails = import_spec['curator_emails'] + dc_email_aliases = [_ALERT_EMAIL_ADDR, _DEBUG_EMAIL_ADDR] time_start = time.time() try: self._import_one_helper( @@ -294,17 +296,11 @@ def _import_one( import_spec=import_spec, ) time_taken = '{0:.2f}'.format(time.time() - time_start) - if self.notifier: - msg = f'Successful Import: {import_name} ({absolute_import_name})\nn' - msg += f'Script execution time taken = {time_taken}s' - self.notifier.send( - subject=f'Import Automation Success - {import_name}', - body=msg, - receiver_addresses=[_DEBUG_EMAIL_ADDR], - ) + logging.info(f'Import Automation Success - {import_name}') + logging.info(f'Script execution time taken = {time_taken}s') except Exception as exc: - if self.notifier: + if self.notifier and not self.config.disable_email_notifications: msg = f'Failed Import: {import_name} ({absolute_import_name})\n\n' msg += f'{_SEE_LOGS_MESSAGE}\n\n' msg += f'Stack Trace: \n' @@ -312,7 +308,7 @@ def _import_one( self.notifier.send( subject=f'Import Automation Failure - {import_name}', body=msg, - receiver_addresses=[_ALERT_EMAIL_ADDR, _DEBUG_EMAIL_ADDR], + receiver_addresses=dc_email_aliases+ curator_emails, ) raise exc