BTHLABS-66: Prepping for public release: Take one

This commit is contained in:
2025-11-18 20:47:07 +01:00
parent 16a9c73624
commit 20fa33abeb
84 changed files with 839 additions and 631 deletions

View File

@@ -79,3 +79,17 @@ class AuthKeysService:
raise self.NotFound(
f'Auth Key not found: key=`{key}`',
) from exception
def clean_expired_auth_keys(self) -> int:
current_timestamp = now()
cutoff_timestamp = current_timestamp - datetime.timedelta(
seconds=(settings.AUTH_KEY_TTL + 5),
)
deleted, _ = AuthKey.active_objects.\
filter(
created_at__lte=cutoff_timestamp,
).\
delete()
return deleted

View File

@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import annotations
import logging
from celery import shared_task
from django import db
from hotpocket_backend.apps.accounts.services import AuthKeysService
LOGGER = logging.getLogger(__name__)
@shared_task
def clean_expired_auth_keys():
with db.transaction.atomic():
deleted_count = AuthKeysService().clean_expired_auth_keys()
LOGGER.debug(
'Deleted expired AuthKey objects: deleted_count=`%d`', deleted_count,
)