refactor(api): type messages cleanup stats with MessagesCleanStatsDict TypedDict (#34527)

This commit is contained in:
YBoy 2026-04-03 14:29:41 +02:00 committed by GitHub
parent 0f051d5886
commit 8a398f3105
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,7 +3,7 @@ import logging
import random import random
import time import time
from collections.abc import Sequence from collections.abc import Sequence
from typing import TYPE_CHECKING, cast from typing import TYPE_CHECKING, TypedDict, cast
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy import delete, select, tuple_ from sqlalchemy import delete, select, tuple_
@ -158,6 +158,13 @@ class MessagesCleanupMetrics:
self._record(self._job_duration_seconds, job_duration_seconds, attributes) self._record(self._job_duration_seconds, job_duration_seconds, attributes)
class MessagesCleanStatsDict(TypedDict):
batches: int
total_messages: int
filtered_messages: int
total_deleted: int
class MessagesCleanService: class MessagesCleanService:
""" """
Service for cleaning expired messages based on retention policies. Service for cleaning expired messages based on retention policies.
@ -299,7 +306,7 @@ class MessagesCleanService:
task_label=task_label, task_label=task_label,
) )
def run(self) -> dict[str, int]: def run(self) -> MessagesCleanStatsDict:
""" """
Execute the message cleanup operation. Execute the message cleanup operation.
@ -319,7 +326,7 @@ class MessagesCleanService:
job_duration_seconds=time.monotonic() - run_start, job_duration_seconds=time.monotonic() - run_start,
) )
def _clean_messages_by_time_range(self) -> dict[str, int]: def _clean_messages_by_time_range(self) -> MessagesCleanStatsDict:
""" """
Clean messages within a time range using cursor-based pagination. Clean messages within a time range using cursor-based pagination.
@ -334,7 +341,7 @@ class MessagesCleanService:
Returns: Returns:
Dict with statistics: batches, filtered_messages, total_deleted Dict with statistics: batches, filtered_messages, total_deleted
""" """
stats = { stats: MessagesCleanStatsDict = {
"batches": 0, "batches": 0,
"total_messages": 0, "total_messages": 0,
"filtered_messages": 0, "filtered_messages": 0,