1
0
Fork 0

Move to redis and fix a bunch of things

This commit is contained in:
Mouse Reeve 2020-03-31 16:31:33 -07:00
parent ca26a712c3
commit bb04a40044
14 changed files with 286 additions and 50 deletions

42
fedireads/tasks.py Normal file
View file

@ -0,0 +1,42 @@
''' background tasks '''
from celery import Celery
import os
from fedireads import models
from fedireads import status as status_builder
from fedireads.outgoing import get_or_create_remote_user
from fedireads import settings
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'fr_celery.settings')
app = Celery(
'tasks',
broker=settings.CELERY_BROKER,
)
@app.task
def handle_incoming_favorite(activity):
''' ugh '''
print('here we go')
try:
status_id = activity['object'].split('/')[-1]
print(status_id)
status = models.Status.objects.get(id=status_id)
liker = get_or_create_remote_user(activity['actor'])
except (models.Status.DoesNotExist, models.User.DoesNotExist):
print('gonna return')
return
print('got the status okay')
if not liker.local:
status_builder.create_favorite_from_activity(liker, activity)
status_builder.create_notification(
status.user,
'FAVORITE',
related_user=liker,
related_status=status,
)
print('done')