Only send a maximum of 20 interest emails
This commit is contained in:
parent
32585495be
commit
5f302a0de7
|
@ -314,25 +314,28 @@ 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
|
||||||
|
|
||||||
interests = models.Interest.objects.filter(
|
with transaction.atomic():
|
||||||
course=session.course,
|
interests = models.Interest.objects.filter(
|
||||||
satisfied_by__isnull=True,
|
course=session.course,
|
||||||
user__member__paused_date__isnull=True
|
satisfied_by__isnull=True,
|
||||||
)
|
user__member__paused_date__isnull=True
|
||||||
|
)[: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)
|
||||||
|
|
||||||
num_satisfied = interests.update(satisfied_by=session)
|
interest_ids = interests.values('id')
|
||||||
logging.info('Satisfied %s interests.', num_satisfied)
|
num_satisfied = models.Interest.objects.filter(id__in=interest_ids).update(satisfied_by=session)
|
||||||
|
|
||||||
|
logging.info('Satisfied %s interests.', num_satisfied)
|
||||||
|
|
||||||
def generate_ical(self, session):
|
def generate_ical(self, session):
|
||||||
cal = icalendar.Calendar()
|
cal = icalendar.Calendar()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user