diff --git a/main/settings.py b/main/settings.py index e8f187e2d0..8332466b5f 100644 --- a/main/settings.py +++ b/main/settings.py @@ -1026,6 +1026,10 @@ offset=timedelta(seconds=KEYCLOAK_ORG_SYNC_OFFSET), ), }, + "clear-expired-tokens": { + "task": "main.tasks.clear_expired_tokens", + "schedule": crontab(minute=0, hour=9, day_of_week=1), # every week + }, } # Hijack diff --git a/main/tasks.py b/main/tasks.py new file mode 100644 index 0000000000..f461dd988c --- /dev/null +++ b/main/tasks.py @@ -0,0 +1,15 @@ +import logging + +from celery import shared_task +from django.core.management import call_command + +log = logging.getLogger(__name__) + + +@shared_task +def run_cleartokens(): + try: + call_command("cleartokens") + log.info("Successfully ran cleartokens management command.") + except Exception: + log.exception("Error running cleartokens")