Add task to refresh actor data in the cache (#1392)
This commit is contained in:
parent
2312a3b780
commit
804d8bcefd
3 changed files with 34 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ import json
|
|||
import logging
|
||||
import os
|
||||
import requests
|
||||
from requests import HTTPError
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import transaction
|
||||
|
|
@ -17,6 +18,7 @@ from funkwhale_api.common import preferences
|
|||
from funkwhale_api.common import models as common_models
|
||||
from funkwhale_api.common import session
|
||||
from funkwhale_api.common import utils as common_utils
|
||||
from funkwhale_api.federation import actors as actors_utils
|
||||
from funkwhale_api.moderation import mrf
|
||||
from funkwhale_api.music import models as music_models
|
||||
from funkwhale_api.taskapp import celery
|
||||
|
|
@ -625,3 +627,29 @@ def fetch_collection(url, max_pages, channel, is_page=False):
|
|||
results["errored"],
|
||||
)
|
||||
return results
|
||||
|
||||
|
||||
@celery.app.task(name="federation.refresh_actor_data")
|
||||
def refresh_actor_data():
|
||||
actors = models.Actor.objects.all().prefetch_related()
|
||||
for actor in actors:
|
||||
try:
|
||||
data = actors_utils.get_actor_data(actor.fid)
|
||||
except HTTPError as e:
|
||||
logger.info(
|
||||
f"Actor couldn't be fetch because of the following exeption : {e!r}"
|
||||
)
|
||||
if e.response.status_code == 410:
|
||||
logger.info("Purging actor : {actor.fid!r}")
|
||||
purge_actors([actor.id], [actor.domain])
|
||||
continue
|
||||
continue
|
||||
except Exception as e:
|
||||
logger.info(
|
||||
f"Actor couldn't be fetch because of the following exeption : {e!r}"
|
||||
)
|
||||
continue
|
||||
serializer = serializers.ActorSerializer(data=data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
serializer.save(last_fetch_date=timezone.now())
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue