Skip to content

Commit

Permalink
Fixes bug where email "from" address is not set (#359)
Browse files Browse the repository at this point in the history
* Make logging more verbose

* Fix bug where email from address goes unset

* Update template signatures
  • Loading branch information
djperrefort authored Aug 6, 2024
1 parent 76fcf98 commit 05402df
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
11 changes: 8 additions & 3 deletions keystone_api/apps/allocations/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def send_expiry_notification_for_request(user: User, request: AllocationRequest)
"""

# There are no notifications if the allocation does not expire
log.debug(f'Checking notifications for user {user.username} on request #{request.id}')
log.debug(f'Checking notifications for user {user.username} on request #{request.id}.')
if not request.expire:
log.debug('Request does not expire')
return
Expand All @@ -145,7 +145,7 @@ def send_expiry_notification_for_request(user: User, request: AllocationRequest)
)

# Exit early if we have not hit a threshold yet
log.debug(f'Request expires in {days_until_expire} days with next threshold at {next_threshold} days.')
log.debug(f'Request #{request.id} expires in {days_until_expire} days with next threshold at {next_threshold} days.')
if next_threshold is None:
return

Expand All @@ -161,7 +161,7 @@ def send_expiry_notification_for_request(user: User, request: AllocationRequest)
log.debug(f'Existing notification found.')

else:
log.debug(f'Sending new notification for request #{request.id}.')
log.debug(f'Sending new notification for request #{request.id} to user {user.username}.')
send_notification_template(
user=user,
subject=f'Allocation Expires on {request.expire}',
Expand All @@ -185,6 +185,7 @@ def send_expiry_notifications() -> None:
expire__gte=timezone.now() - timedelta(days=7)
).all()

failed = False
for request in expiring_requests:
for user in request.group.get_all_members():

Expand All @@ -193,3 +194,7 @@ def send_expiry_notifications() -> None:

except Exception as error:
log.exception(f'Error notifying user {user.username} for request #{request.id}: {error}')
failed = True

if failed:
raise RuntimeError('Task failed with one or more errors. See logs for details.')
5 changes: 2 additions & 3 deletions keystone_api/apps/allocations/templates/expiration_email.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
This notification is to remind you your HPC compute allocation <strong>"{{ request_title }}"</strong>
is set to expire in {{ days_to_expire }} days on {{ request_expire }}.
</p>
<p>
Yours,<br>The Keystone Allocation Bot
</p>
<p>Sincerely,</p>
<p>The keystone HPC utility</p>
3 changes: 2 additions & 1 deletion keystone_api/apps/notifications/templates/general.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@

<p>{{ message }}</p>

<p>Sincerely,<br>The keystone HPC utility</p>
<p>Sincerely,</p>
<p>The keystone HPC utility</p>
2 changes: 1 addition & 1 deletion keystone_api/main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@

# Email server

EMAIL_FROM_ADDRESS = env.str('EMAIL_FROM_ADDRESS', '[email protected]')
if _email_path := env.get_value('DEBUG_EMAIL_DIR', default=None):
EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend'
EMAIL_FILE_PATH = _email_path
Expand All @@ -189,7 +190,6 @@
EMAIL_HOST_USER = env.str('EMAIL_HOST_USER', '')
EMAIL_HOST_PASSWORD = env.str('your_email_password', '')
EMAIL_USE_TLS = env.bool('EMAIL_USE_TLS', False)
EMAIL_FROM_ADDRESS = env.str('EMAIL_FROM_ADDRESS', '[email protected]')

# Database

Expand Down

0 comments on commit 05402df

Please sign in to comment.