2019-02-27 00:45:00 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
|
|
|
|
from celery import shared_task
|
2019-03-11 02:06:45 +00:00
|
|
|
from ops.celery.decorator import register_as_period_task
|
|
|
|
from django.contrib.sessions.models import Session
|
|
|
|
from django.utils import timezone
|
2023-02-02 07:57:06 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2019-02-27 00:45:00 +00:00
|
|
|
|
2019-03-11 02:06:45 +00:00
|
|
|
|
2024-09-09 10:54:33 +00:00
|
|
|
@shared_task(
|
|
|
|
verbose_name=_('Clean expired session'),
|
|
|
|
description=_(
|
|
|
|
"""
|
|
|
|
Since user logins create sessions, the system will clean up expired sessions every 24
|
|
|
|
hours
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
)
|
2023-02-17 09:14:53 +00:00
|
|
|
@register_as_period_task(interval=3600 * 24)
|
2019-03-11 02:06:45 +00:00
|
|
|
def clean_django_sessions():
|
|
|
|
Session.objects.filter(expire_date__lt=timezone.now()).delete()
|