Disable inactive club sites #68

Merged
r389li merged 8 commits from disable-inactive-club-sites into master 2022-07-22 23:52:01 -04:00
1 changed files with 11 additions and 0 deletions
Showing only changes of commit 2a145cd83a - Show all commits

View File

@ -204,6 +204,8 @@ class ClubWebHostingService:
for club in all_clubs
if not any(map(lambda member: member in active_club_reps, club.members))
]
# STEP 1: update the Apache configs
with self.begin_transaction():
clubs_to_disable = [
club.cn
@ -218,17 +220,26 @@ class ClubWebHostingService:
self.commit()
# self.clubs is set to None once the transaction closes, so make a copy now
clubs_info = self.clubs.copy()
# STEP 2: send emails to clubs whose websites were disabled
clubs_who_were_not_notified = set()
for club_name in clubs_to_disable:
address = clubs_info['email']
r389li marked this conversation as resolved
Review

Let's catch the specific exception that send_club_website_has_been_disabled_message raises.

Let's catch the specific exception that `send_club_website_has_been_disabled_message` raises.
Review

Actually, in this case, I think we really do want to catch all exceptions. Here's why:

  1. We don't know exactly which Exceptions this function will raise. Sending an email can fail for a lot of different reasons (host is unreachable, host refuses connection, authentication fails, message is rejected, etc.).
  2. We don't want the failure of a single recipient to affect the other recipients. So no matter how a particular message fails, we want to keep on going.
Actually, in this case, I think we really do want to catch all exceptions. Here's why: 1. We don't know exactly which Exceptions this function will raise. Sending an email can fail for a lot of different reasons (host is unreachable, host refuses connection, authentication fails, message is rejected, etc.). 2. We don't want the failure of a single recipient to affect the other recipients. So no matter how a particular message fails, we want to keep on going.
if address is None:
clubs_who_were_not_notified.add(club_name)
continue
try:
mail_srv.send_club_website_has_been_disabled_message(club_name, address)
except Exception:
trace = traceback.format_exc()
logger.error(f'Failed to send email to {address}:\n{trace}')
clubs_who_were_not_notified.add(club_name)
# STEP 3: remove inactive club reps from Unix groups
if remove_inactive_club_reps:
for club in all_clubs:
if club.cn in clubs_who_were_not_notified:
continue
# club.members gets modified after calling club.remove_member(),
# so we need to make a copy
members = club.members.copy()