Skip to content

Commit

Permalink
Don't update the last_send_time as often
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbyt3r committed Jul 13, 2023
1 parent 4429d12 commit 5cadbaf
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions uber/tasks/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def send_automated_emails():
if not (c.DEV_BOX or c.SEND_EMAILS):
return None

expiration = timedelta(hours=1)
quantity_sent = 0
start_time = time()
with Session() as session:
Expand All @@ -176,7 +177,7 @@ def send_automated_emails():
if automated_email.currently_sending:
log.info(automated_email.ident + " is marked as currently sending")
if automated_email.last_send_time:
if (datetime.now() - automated_email.last_send_time) < timedelta(hours=1):
if (datetime.now() - automated_email.last_send_time) < expiration:
# Looks like another thread is still running and hasn't timed out.
continue
automated_email.currently_sending = True
Expand All @@ -199,9 +200,10 @@ def send_automated_emails():
quantity_sent += 1
else:
unapproved_count += 1
automated_email.last_send_time = datetime.now()
session.add(automated_email)
session.commit()
if datetime.now() - automated_email.last_send_time > (expiration / 2):
automated_email.last_send_time = datetime.now()
session.add(automated_email)
session.commit()

automated_email.unapproved_count = unapproved_count
automated_email.currently_sending = False
Expand Down

0 comments on commit 5cadbaf

Please sign in to comment.