mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 06:42:16 +00:00
Add further error checking to the Reddit tasks, gracefully handle issues
This commit is contained in:
@@ -14,8 +14,8 @@ class send_reddit_message(Task):
|
|||||||
logger = self.get_logger(**kwargs)
|
logger = self.get_logger(**kwargs)
|
||||||
|
|
||||||
logger.info("Sending Reddit message to %s" % to)
|
logger.info("Sending Reddit message to %s" % to)
|
||||||
ib = Inbox(username=settings.REDDIT_USER, password=settings.REDDIT_PASSWORD)
|
|
||||||
try:
|
try:
|
||||||
|
ib = Inbox(username=settings.REDDIT_USER, password=settings.REDDIT_PASSWORD)
|
||||||
ib.send(to, subject, message)
|
ib.send(to, subject, message)
|
||||||
except (HTTPError, URLError), exc:
|
except (HTTPError, URLError), exc:
|
||||||
logger.error("Error sending message, queueing for retry")
|
logger.error("Error sending message, queueing for retry")
|
||||||
@@ -30,21 +30,19 @@ def process_validations():
|
|||||||
logger = process_validations.get_logger()
|
logger = process_validations.get_logger()
|
||||||
try:
|
try:
|
||||||
inbox = Inbox(settings.REDDIT_USER, settings.REDDIT_PASSWORD)
|
inbox = Inbox(settings.REDDIT_USER, settings.REDDIT_PASSWORD)
|
||||||
|
for msg in inbox:
|
||||||
|
if not msg.was_comment:
|
||||||
|
try:
|
||||||
|
acc = RedditAccount.objects.get(username__iexact=msg.author)
|
||||||
|
if not acc.validated and msg.subject == "Validation: %s" % acc.user.username:
|
||||||
|
logger.info("Validated %s" % acc.user.username)
|
||||||
|
acc.validated = True
|
||||||
|
acc.save()
|
||||||
|
except RedditAccount.DoesNotExist:
|
||||||
|
continue
|
||||||
except (HTTPError, URLError), exc:
|
except (HTTPError, URLError), exc:
|
||||||
logger.error("Error with Reddit, aborting.")
|
logger.error("Error with Reddit, aborting.")
|
||||||
return
|
return
|
||||||
except LoginError, exc:
|
except LoginError, exc:
|
||||||
logger.error("Error logging into Reddit")
|
logger.error("Error logging into Reddit")
|
||||||
return
|
return
|
||||||
|
|
||||||
for msg in inbox:
|
|
||||||
if not msg.was_comment:
|
|
||||||
try:
|
|
||||||
acc = RedditAccount.objects.get(username__iexact=msg.author)
|
|
||||||
if not acc.validated and msg.subject == "Validation: %s" % acc.user.username:
|
|
||||||
logger.info("Validated %s" % acc.user.username)
|
|
||||||
acc.validated = True
|
|
||||||
acc.save()
|
|
||||||
except RedditAccount.DoesNotExist:
|
|
||||||
continue
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user