Add: setup clearing of expired tokens
This commit is contained in:
parent
828c46b27c
commit
433a783c3a
2 changed files with 20 additions and 1 deletions
12
backend/api/authentication/tasks.py
Normal file
12
backend/api/authentication/tasks.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
from celery import shared_task
|
||||||
|
from django.core.management import call_command
|
||||||
|
|
||||||
|
|
||||||
|
@shared_task
|
||||||
|
def flush_expired_tokens():
|
||||||
|
"""Flush expired tokens using Django's call_command"""
|
||||||
|
try:
|
||||||
|
call_command("flushexpiredtokens")
|
||||||
|
return "Successfully flushed expired tokens"
|
||||||
|
except Exception as e:
|
||||||
|
return f"Error flushing tokens: {str(e)}"
|
|
@ -1,6 +1,6 @@
|
||||||
import os
|
import os
|
||||||
from celery import Celery
|
from celery import Celery
|
||||||
# from celery.schedules import crontab
|
from celery.schedules import crontab
|
||||||
|
|
||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")
|
||||||
|
|
||||||
|
@ -8,4 +8,11 @@ app = Celery("Gallery Archiver")
|
||||||
|
|
||||||
app.config_from_object("django.conf:settings", namespace="CELERY")
|
app.config_from_object("django.conf:settings", namespace="CELERY")
|
||||||
|
|
||||||
|
# Configure beat schedule
|
||||||
|
app.conf.beat_schedule = {
|
||||||
|
"auth.flush_expired_tokens": {
|
||||||
|
"task": "api.authentication.tasks.flush_expired_tokens",
|
||||||
|
"schedule": crontab(hour=2, minute=0), # Daily at 2:00 AM
|
||||||
|
},
|
||||||
|
}
|
||||||
app.autodiscover_tasks()
|
app.autodiscover_tasks()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue