summaryrefslogtreecommitdiffstats
path: root/users/models/inbox_message.py
diff options
context:
space:
mode:
authorAndrew Godwin2022-11-27 17:05:31 -0700
committerAndrew Godwin2022-11-27 17:05:31 -0700
commit3b079526a2ea78b68555094ca498faea31022759 (patch)
tree28414e93aa7d412148fbcba6ecd6e2a0b09ecb5f /users/models/inbox_message.py
parent2f443414a7e029f83292873257d2940b5a10cc64 (diff)
downloadtakahe-3b079526a2ea78b68555094ca498faea31022759.tar.gz
takahe-3b079526a2ea78b68555094ca498faea31022759.tar.bz2
takahe-3b079526a2ea78b68555094ca498faea31022759.zip
User fetching and inbox message cleaning
Diffstat (limited to 'users/models/inbox_message.py')
-rw-r--r--users/models/inbox_message.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/users/models/inbox_message.py b/users/models/inbox_message.py
index 589f933..079c572 100644
--- a/users/models/inbox_message.py
+++ b/users/models/inbox_message.py
@@ -1,14 +1,17 @@
from asgiref.sync import sync_to_async
from django.db import models
+from core.models import Config
from stator.models import State, StateField, StateGraph, StatorModel
class InboxMessageStates(StateGraph):
received = State(try_interval=300)
- processed = State()
+ processed = State(try_interval=86400, attempt_immediately=False)
+ purged = State() # This is actually deletion, it will never get here
received.transitions_to(processed)
+ processed.transitions_to(purged)
@classmethod
async def handle_received(cls, instance: "InboxMessage"):
@@ -80,6 +83,11 @@ class InboxMessageStates(StateGraph):
raise ValueError(f"Cannot handle activity of type {unknown}")
return cls.processed
+ @classmethod
+ async def handle_processed(cls, instance: "InboxMessage"):
+ if instance.state_age > Config.system.inbox_message_purge_after:
+ await InboxMessage.objects.filter(pk=instance.pk).adelete()
+
class InboxMessage(StatorModel):
"""