Actor delete, sentry async, faster stator
This commit is contained in:
parent
77643a4fe1
commit
f491fdb56e
|
@ -0,0 +1,10 @@
|
||||||
|
class ActivityPubError(BaseException):
|
||||||
|
"""
|
||||||
|
A problem with an ActivityPub message
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class ActorMismatchError(ActivityPubError):
|
||||||
|
"""
|
||||||
|
The actor is not authorised to do the action we saw
|
||||||
|
"""
|
|
@ -158,7 +158,7 @@ class StatorModel(models.Model):
|
||||||
if settings.SENTRY_ENABLED:
|
if settings.SENTRY_ENABLED:
|
||||||
from sentry_sdk import capture_exception
|
from sentry_sdk import capture_exception
|
||||||
|
|
||||||
capture_exception(e)
|
await sync_to_async(capture_exception, thread_sensitive=False)(e)
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
else:
|
else:
|
||||||
if next_state:
|
if next_state:
|
||||||
|
|
|
@ -5,6 +5,7 @@ import traceback
|
||||||
import uuid
|
import uuid
|
||||||
from typing import List, Optional, Type
|
from typing import List, Optional, Type
|
||||||
|
|
||||||
|
from asgiref.sync import sync_to_async
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
|
@ -46,12 +47,12 @@ class StatorRunner:
|
||||||
if (time.monotonic() - self.last_clean) >= self.schedule_interval:
|
if (time.monotonic() - self.last_clean) >= self.schedule_interval:
|
||||||
print(f"{self.handled} tasks processed so far")
|
print(f"{self.handled} tasks processed so far")
|
||||||
print("Running cleaning and scheduling")
|
print("Running cleaning and scheduling")
|
||||||
self.remove_completed_tasks()
|
|
||||||
for model in self.models:
|
for model in self.models:
|
||||||
asyncio.create_task(model.atransition_clean_locks())
|
asyncio.create_task(model.atransition_clean_locks())
|
||||||
asyncio.create_task(model.atransition_schedule_due())
|
asyncio.create_task(model.atransition_schedule_due())
|
||||||
self.last_clean = time.monotonic()
|
self.last_clean = time.monotonic()
|
||||||
# Calculate space left for tasks
|
# Calculate space left for tasks
|
||||||
|
self.remove_completed_tasks()
|
||||||
space_remaining = self.concurrency - len(self.tasks)
|
space_remaining = self.concurrency - len(self.tasks)
|
||||||
# Fetch new tasks
|
# Fetch new tasks
|
||||||
for model in self.models:
|
for model in self.models:
|
||||||
|
@ -95,7 +96,7 @@ class StatorRunner:
|
||||||
if settings.SENTRY_ENABLED:
|
if settings.SENTRY_ENABLED:
|
||||||
from sentry_sdk import capture_exception
|
from sentry_sdk import capture_exception
|
||||||
|
|
||||||
capture_exception(e)
|
await sync_to_async(capture_exception, thread_sensitive=False)(e)
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
def remove_completed_tasks(self):
|
def remove_completed_tasks(self):
|
||||||
|
|
|
@ -12,6 +12,7 @@ from django.template.defaultfilters import linebreaks_filter
|
||||||
from django.templatetags.static import static
|
from django.templatetags.static import static
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
|
from core.exceptions import ActorMismatchError
|
||||||
from core.html import sanitize_post
|
from core.html import sanitize_post
|
||||||
from core.ld import canonicalise, media_type_from_filename
|
from core.ld import canonicalise, media_type_from_filename
|
||||||
from core.uploads import upload_namer
|
from core.uploads import upload_namer
|
||||||
|
@ -261,6 +262,24 @@ class Identity(StatorModel):
|
||||||
except cls.DoesNotExist:
|
except cls.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def handle_delete_ap(cls, data):
|
||||||
|
"""
|
||||||
|
Takes an incoming update.person message and just forces us to add it
|
||||||
|
to our fetch queue (don't want to bother with two load paths right now)
|
||||||
|
"""
|
||||||
|
# Assert that the actor matches the object
|
||||||
|
if data["actor"] != data["object"]:
|
||||||
|
raise ActorMismatchError(
|
||||||
|
f"Actor {data['actor']} trying to delete identity {data['object']}"
|
||||||
|
)
|
||||||
|
# Find by actor
|
||||||
|
try:
|
||||||
|
actor = cls.by_actor_uri(data["actor"])
|
||||||
|
actor.delete()
|
||||||
|
except cls.DoesNotExist:
|
||||||
|
pass
|
||||||
|
|
||||||
### Actor/Webfinger fetching ###
|
### Actor/Webfinger fetching ###
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -67,7 +67,7 @@ class InboxMessageStates(StateGraph):
|
||||||
case "delete":
|
case "delete":
|
||||||
# If there is no object type, it's probably a profile
|
# If there is no object type, it's probably a profile
|
||||||
if not isinstance(instance.message["object"], dict):
|
if not isinstance(instance.message["object"], dict):
|
||||||
raise ValueError("Cannot handle activity of type delete")
|
await sync_to_async(Identity.handle_delete_ap)(instance.message)
|
||||||
match instance.message_object_type:
|
match instance.message_object_type:
|
||||||
case "tombstone":
|
case "tombstone":
|
||||||
await sync_to_async(Post.handle_delete_ap)(instance.message)
|
await sync_to_async(Post.handle_delete_ap)(instance.message)
|
||||||
|
|
Loading…
Reference in New Issue