From 3de75acfc41e61efccea95679713f5f0ff4afcda Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Mon, 8 Nov 2010 14:37:44 +0000 Subject: [PATCH] Offload reddit messages to a task --- hr/views.py | 9 ++------- reddit/tasks.py | 9 +++++++++ 2 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 reddit/tasks.py diff --git a/hr/views.py b/hr/views.py index 0b117a2..6e45954 100644 --- a/hr/views.py +++ b/hr/views.py @@ -30,13 +30,8 @@ def send_message(application, message_type, note=None): pass if len(application.user.redditaccount_set.all()) > 0: - from reddit.api import Inbox, LoginError - try: - ib = Inbox(settings.REDDIT_USER, settings.REDDIT_PASSWORD) - except LoginError: - pass - else: - ib.send(application.user.redditaccount_set.all()[0].username, subject, message) + from reddit.tasks import send_reddit_message + send_reddit_message.delay(to=application.user.redditaccount_set.all()[0].username, subject=subject, message=message) def check_permissions(user, application=None): diff --git a/reddit/tasks.py b/reddit/tasks.py new file mode 100644 index 0000000..c4c7bff --- /dev/null +++ b/reddit/tasks.py @@ -0,0 +1,9 @@ +from celery.decorators import task +from reddit.api import Inbox +import settings + +@task(ignore_result=True) +def send_reddit_message(to, subject, message): + ib = Inbox(settings.REDDIT_USER, settings.REDDIT_PASSWORD) + ib.send(to, subject, message) +