Add task to refresh actor data in the cache (#1392)
This commit is contained in:
parent
2312a3b780
commit
804d8bcefd
|
@ -841,6 +841,11 @@ CELERY_BEAT_SCHEDULE = {
|
|||
"schedule": crontab(day_of_week="1", minute="0", hour="2"),
|
||||
"options": {"expires": 60 * 60 * 24},
|
||||
},
|
||||
"federation.refresh_actor_data": {
|
||||
"task": "federation.refresh_actor_data",
|
||||
"schedule": crontab(minute="0", hour="*/5"),
|
||||
"options": {"expires": 60 * 60},
|
||||
},
|
||||
}
|
||||
|
||||
if env.bool("ADD_ALBUM_TAGS_FROM_TRACKS", default=True):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Add task to refresh actor data in the cache (#1392)
|
Loading…
Reference in New Issue