Remove interest-satisfying atomic()

This commit is contained in:
Tanner Collin 2023-03-01 17:59:19 +00:00
parent 0f5dbee24b
commit f5ff777aa9

View File

@ -313,28 +313,27 @@ class SessionViewSet(Base, List, Retrieve, Create, Update):
logging.info('Session is in the past or too soon, not sending interest emails.') logging.info('Session is in the past or too soon, not sending interest emails.')
return return
with transaction.atomic(): interests = models.Interest.objects.filter(
interests = models.Interest.objects.filter( course=session.course,
course=session.course, satisfied_by__isnull=True,
satisfied_by__isnull=True, user__member__paused_date__isnull=True
user__member__paused_date__isnull=True )[:20]
)[:20]
for num, interest in enumerate(interests): for num, interest in enumerate(interests):
msg = 'Sending email {} / {}...'.format(num+1, len(interests)) msg = 'Sending email {} / {}...'.format(num+1, len(interests))
if data['request_id']: utils_stats.set_progress(data['request_id'], msg, replace=True) if data['request_id']: utils_stats.set_progress(data['request_id'], msg, replace=True)
try: try:
utils_email.send_interest_email(interest) utils_email.send_interest_email(interest)
except BaseException as e: except BaseException as e:
msg = 'Problem sending interest email: ' + str(e) msg = 'Problem sending interest email: ' + str(e)
logger.exception(msg) logger.exception(msg)
utils.alert_tanner(msg) utils.alert_tanner(msg)
interest_ids = interests.values('id') interest_ids = interests.values('id')
num_satisfied = models.Interest.objects.filter(id__in=interest_ids).update(satisfied_by=session) num_satisfied = models.Interest.objects.filter(id__in=interest_ids).update(satisfied_by=session)
logging.info('Satisfied %s interests.', num_satisfied) logging.info('Satisfied %s interests.', num_satisfied)
def generate_ical(self, session): def generate_ical(self, session):
cal = icalendar.Calendar() cal = icalendar.Calendar()