Skip to content

Commit

Permalink
Hopefully fixed timezone related bug
Browse files Browse the repository at this point in the history
  • Loading branch information
DumboOctopus committed Nov 24, 2020
1 parent 7909471 commit 50ef4d2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
17 changes: 10 additions & 7 deletions meow/scheduler/management/commands/sendposts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.utils import timezone
from django.conf import settings


from datetime import datetime, timedelta
from facepy import GraphAPI
from facepy.exceptions import FacepyError
Expand Down Expand Up @@ -96,22 +97,24 @@ def handle(self, *args, **options):
# Make sure this post should actually be sent out. If it's more than
# 20 minutes late, we're gonna mark it as an error and send an error
# message.
# 11/23/2020 5:15:35 PM01:15:35 worker.1 | sent_error_text: NoneError: Arts 2020-11-23 17:15:35.661913 -- Would have sent more than 20 minutes late.
send_date = datetime.combine(post.pub_date, post.pub_time)
send_grace_period = timedelta(minutes=20)
if (timezone.now() - timezone.make_aware(send_date)) > send_grace_period:
tmp_current_time = timezone.localtime(timezone.now())
tmp_send_datetime = timezone.make_aware(send_date)
time_since_scheduled_time = (tmp_current_time - tmp_send_datetime)
if time_since_scheduled_time > send_grace_period:
try:
post.sending = False
post.log_error(
"Would have sent more than 20 minutes late.", post.section, True)

# print out all of the model's fields

debugging = SMPost.objects.filter(id=post.id)
logger.error("Would have sent more than 20 minutes late")
debug_str = "Model Fields\n"
for key, value in debugging.all().values()[0].items():
debug_str += str(key) + ": " + str(value) + "\n"
logger.error(debug_str)
logger.error("Current_time" + str(tmp_current_time))
logger.error("Datetime for post" + str(tmp_send_datetime))

post.print_info_to_error_log()

post.sending = False
post.sent = True
Expand Down
12 changes: 12 additions & 0 deletions meow/scheduler/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import urllib
from django.core.mail import send_mail
from bs4 import BeautifulSoup
import logging

logger = logging.getLogger(__name__)


class SMPostTag(models.Model):
"""
Expand Down Expand Up @@ -181,6 +185,14 @@ def post_status_string(self):
self.post_statuses.SENDING: "Sending...",
}[self.post_status()]

def print_info_to_error_log(self):
debugging = SMPost.objects.filter(id=self.id)

debug_str = "Model Fields\n"
for key, value in debugging.all().values()[0].items():
debug_str += str(key) + ": " + str(value) + "\n"
logger.error(debug_str)

# Returns a 2-tuple with (canonical URL, sending URL)
# Either both are set or neither are set
def get_send_url(self):
Expand Down

0 comments on commit 50ef4d2

Please sign in to comment.