mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 06:42:16 +00:00
Offload reddit messages to a task
This commit is contained in:
@@ -30,13 +30,8 @@ def send_message(application, message_type, note=None):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
if len(application.user.redditaccount_set.all()) > 0:
|
if len(application.user.redditaccount_set.all()) > 0:
|
||||||
from reddit.api import Inbox, LoginError
|
from reddit.tasks import send_reddit_message
|
||||||
try:
|
send_reddit_message.delay(to=application.user.redditaccount_set.all()[0].username, subject=subject, message=message)
|
||||||
ib = Inbox(settings.REDDIT_USER, settings.REDDIT_PASSWORD)
|
|
||||||
except LoginError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
ib.send(application.user.redditaccount_set.all()[0].username, subject, message)
|
|
||||||
|
|
||||||
|
|
||||||
def check_permissions(user, application=None):
|
def check_permissions(user, application=None):
|
||||||
|
|||||||
9
reddit/tasks.py
Normal file
9
reddit/tasks.py
Normal file
@@ -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)
|
||||||
|
|
||||||
Reference in New Issue
Block a user