mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-24 11:38:39 +02:00
Merge pull request #1327 from cisagov/nmb/email-sent-incremental
Set transition domain's email_sent flag as the emails are sent
This commit is contained in:
commit
bcbf5557ff
1 changed files with 14 additions and 10 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
import logging
|
||||
import copy
|
||||
import time
|
||||
|
||||
from django.core.management import BaseCommand
|
||||
from registrar.models import TransitionDomain
|
||||
|
@ -65,8 +66,6 @@ class Command(BaseCommand):
|
|||
self.send_emails()
|
||||
logger.info("done sending emails")
|
||||
|
||||
self.update_domains_as_sent()
|
||||
|
||||
logger.info("done sending emails and updating transition_domains")
|
||||
else:
|
||||
logger.info("not sending emails")
|
||||
|
@ -114,6 +113,9 @@ class Command(BaseCommand):
|
|||
if len(self.emails_to_send) > 0:
|
||||
for email_data in self.emails_to_send:
|
||||
self.send_email(email_data)
|
||||
# wait 1/10 second until sending the next email to keep us
|
||||
# safely under a rate of 10 emails per second
|
||||
time.sleep(0.1)
|
||||
else:
|
||||
logger.info("no emails to send")
|
||||
|
||||
|
@ -143,11 +145,13 @@ class Command(BaseCommand):
|
|||
# to True
|
||||
for domain in email_data["domains"]:
|
||||
self.domains_with_errors.append(domain)
|
||||
|
||||
def update_domains_as_sent(self):
|
||||
"""set email_sent to True in all transition_domains which have
|
||||
been processed successfully"""
|
||||
for transition_domain in self.transition_domains:
|
||||
if transition_domain.domain_name not in self.domains_with_errors:
|
||||
transition_domain.email_sent = True
|
||||
transition_domain.save()
|
||||
else:
|
||||
# email was sent no exception, mark all these transition domains
|
||||
# as email_sent.
|
||||
this_email = email_data["email"]
|
||||
for domain_name in email_data["domains"]:
|
||||
# self.transition_domains is a queryset so we can sub-select
|
||||
# from it and use the objects to mark them as sent
|
||||
this_transition_domain = self.transition_domains.get(username=this_email, domain_name=domain_name)
|
||||
this_transition_domain.email_sent = True
|
||||
this_transition_domain.save()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue