From bb0ee1b15262464964bbb3a4e6d7b68a0c5651c8 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sun, 1 Jan 2023 13:10:54 -0700 Subject: [PATCH] Purge failing inbox messages too --- core/models/config.py | 1 - users/models/inbox_message.py | 18 +++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/core/models/config.py b/core/models/config.py index a05c33a..7dda07b 100644 --- a/core/models/config.py +++ b/core/models/config.py @@ -220,7 +220,6 @@ class Config(models.Model): identity_min_length: int = 2 identity_max_per_user: int = 5 identity_max_age: int = 24 * 60 * 60 - inbox_message_purge_after: int = 24 * 60 * 60 public_timeline: bool = True hashtag_unreviewed_are_public: bool = True diff --git a/users/models/inbox_message.py b/users/models/inbox_message.py index 2b4e816..00e5b74 100644 --- a/users/models/inbox_message.py +++ b/users/models/inbox_message.py @@ -1,17 +1,19 @@ 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(try_interval=86400, attempt_immediately=False) - purged = State() # This is actually deletion, it will never get here + processed = State(externally_progressed=True) + purge = State(try_interval=300) + purged = State() # Not actually real, nothing gets here received.transitions_to(processed) - processed.transitions_to(purged) + processed.times_out_to(purge, 86400 * 1) + received.times_out_to(purge, 86400 * 3) + purge.transitions_to(purged) @classmethod async def handle_received(cls, instance: "InboxMessage"): @@ -151,9 +153,11 @@ class InboxMessageStates(StateGraph): 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() + async def handle_purge(cls, instance: "InboxMessage"): + """ + Just delete them! + """ + await InboxMessage.objects.filter(pk=instance.pk).adelete() class InboxMessage(StatorModel):