Skip to content

Commit

Permalink
Update import notification settings
Browse files Browse the repository at this point in the history
  • Loading branch information
vish-cs committed Dec 27, 2024
1 parent 4bdde25 commit 998e712
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 2 additions & 0 deletions import-automation/executor/app/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 6 additions & 10 deletions import-automation/executor/app/executor/import_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -294,25 +296,19 @@ 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'
msg += f'{exc}'
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

Expand Down

0 comments on commit 998e712

Please sign in to comment.