This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/passbook/core/tasks.py
2020-09-15 12:53:02 +02:00

23 lines
617 B
Python

"""passbook core tasks"""
from django.utils.timezone import now
from structlog import get_logger
from passbook.core.models import ExpiringModel
from passbook.root.celery import CELERY_APP
LOGGER = get_logger()
@CELERY_APP.task()
def clean_expired_models():
"""Remove expired objects"""
for cls in ExpiringModel.__subclasses__():
cls: ExpiringModel
amount, _ = (
cls.objects.all()
.exclude(expiring=False)
.exclude(expiring=True, expires__gt=now())
.delete()
)
LOGGER.debug("Deleted expired models", model=cls, amount=amount)