Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

email: don't send emails when notifications are disabled #407

Conversation

giuseppe-steduto
Copy link
Member

@giuseppe-steduto giuseppe-steduto force-pushed the not-send-emails-notifications-disabled branch from 2c8e733 to 3343ce3 Compare August 24, 2023 08:18
@codecov
Copy link

codecov bot commented Aug 24, 2023

Codecov Report

Merging #407 (0fa088a) into master (2e20d17) will increase coverage by 0.10%.
The diff coverage is 60.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #407      +/-   ##
==========================================
+ Coverage   35.70%   35.80%   +0.10%     
==========================================
  Files          26       26              
  Lines        1560     1564       +4     
==========================================
+ Hits          557      560       +3     
- Misses       1003     1004       +1     
Files Changed Coverage Δ
reana_commons/version.py 0.00% <0.00%> (ø)
reana_commons/email.py 68.42% <75.00%> (+0.77%) ⬆️

@giuseppe-steduto giuseppe-steduto marked this pull request as ready for review August 24, 2023 11:53
message = EmailMessage()
message["From"] = f"REANA platform <{sender_email}>"
message["To"] = receiver_email
message["Subject"] = subject
message.set_content(body)

if not REANA_NOTIFICATIONS_ENABLED:
logging.info(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can keep this like this for now, but for the future we should improve this as we are mixing the logic to send emails (e.g. server connection, message encoding, etc.) with REANA's notification logic (e.g. do not send emails if notifications are disabled). Not only that, the behaviour of this function depends a lot on global state, thus making this function hard to test and hard to use properly.

On another note, what do you think about throwing an exception instead of just logging this? We already have REANAEmailNotificationError, and we are already catching it in most places, except for _send_confirmation_email. In this way, we also avoid having to check REANA_NOTIFICATIONS_ENABLED to understand if the email was actually sent or not

@giuseppe-steduto giuseppe-steduto force-pushed the not-send-emails-notifications-disabled branch from 3343ce3 to a400ea6 Compare September 4, 2023 08:53
Copy link
Member

@mdonadoni mdonadoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Could you please also add the release commit to this PR, so that we can already start releasing the new version of reana-commons?

@mdonadoni mdonadoni force-pushed the not-send-emails-notifications-disabled branch from ef8303c to 0fa088a Compare September 5, 2023 10:36
@mdonadoni mdonadoni merged commit 0fa088a into reanahub:master Sep 5, 2023
15 checks passed
@mdonadoni
Copy link
Member

Rebased and merged!

@mdonadoni mdonadoni mentioned this pull request Sep 1, 2023
23 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

helm: sending emails fails if notifications are disabled
2 participants