You've already forked hotpocket
BTHLABS-66: Prepping for public release: Take one
This commit is contained in:
@@ -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
|
||||
|
||||
20
services/backend/hotpocket_backend/apps/accounts/tasks.py
Normal file
20
services/backend/hotpocket_backend/apps/accounts/tasks.py
Normal 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,
|
||||
)
|
||||
Reference in New Issue
Block a user