From dbddf5c11b9b0552da3f996dc68aa50f304d9faa Mon Sep 17 00:00:00 2001 From: Anna Date: Tue, 20 Jan 2026 10:58:10 -0500 Subject: [PATCH 1/6] Add celery task to run cleartokens every week --- main/settings.py | 4 ++++ main/tasks.py | 13 +++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 main/tasks.py diff --git a/main/settings.py b/main/settings.py index e8f187e2d0..a7dbd42cf3 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..b82d939731 --- /dev/null +++ b/main/tasks.py @@ -0,0 +1,13 @@ +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 as e: + log.error(f"Error running cleartokens: {e}") From c2e6da0061d729f61926d03f5f7e0ab32f63b917 Mon Sep 17 00:00:00 2001 From: Anna Date: Wed, 21 Jan 2026 09:40:29 -0500 Subject: [PATCH 2/6] fix errors --- main/tasks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main/tasks.py b/main/tasks.py index b82d939731..255135e1df 100644 --- a/main/tasks.py +++ b/main/tasks.py @@ -9,5 +9,5 @@ def run_cleartokens(): try: call_command("cleartokens") log.info("Successfully ran cleartokens management command.") - except Exception as e: - log.error(f"Error running cleartokens: {e}") + except Exception as e: # pylint: disable=broad-except + log.error("Error running cleartokens: %s", e) From 862caf19f4ed9810016b20a7de3488b8b82a583e Mon Sep 17 00:00:00 2001 From: Anna Date: Wed, 21 Jan 2026 09:41:59 -0500 Subject: [PATCH 3/6] format --- main/settings.py | 2 +- main/tasks.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/main/settings.py b/main/settings.py index a7dbd42cf3..8332466b5f 100644 --- a/main/settings.py +++ b/main/settings.py @@ -1028,7 +1028,7 @@ }, "clear-expired-tokens": { "task": "main.tasks.clear_expired_tokens", - "schedule": crontab(minute=0, hour=9, day_of_week=1), # every week + "schedule": crontab(minute=0, hour=9, day_of_week=1), # every week }, } diff --git a/main/tasks.py b/main/tasks.py index 255135e1df..4e21ce2d35 100644 --- a/main/tasks.py +++ b/main/tasks.py @@ -1,9 +1,11 @@ import logging + from celery import shared_task from django.core.management import call_command log = logging.getLogger(__name__) + @shared_task def run_cleartokens(): try: From dbd16ac368a85a47d6694fbfbfa1bd6bcc52636e Mon Sep 17 00:00:00 2001 From: Anna Date: Wed, 21 Jan 2026 10:26:56 -0500 Subject: [PATCH 4/6] exception --- main/tasks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main/tasks.py b/main/tasks.py index 4e21ce2d35..db58080bc7 100644 --- a/main/tasks.py +++ b/main/tasks.py @@ -11,5 +11,5 @@ def run_cleartokens(): try: call_command("cleartokens") log.info("Successfully ran cleartokens management command.") - except Exception as e: # pylint: disable=broad-except - log.error("Error running cleartokens: %s", e) + except Exception as e: # noqa: BLE001 + log.exception("Error running cleartokens: %s", e) From c775aaf8b9b5dedab3b6b0f1de9572cb68a97a69 Mon Sep 17 00:00:00 2001 From: Anna Date: Wed, 21 Jan 2026 10:34:03 -0500 Subject: [PATCH 5/6] removing e --- main/tasks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main/tasks.py b/main/tasks.py index db58080bc7..a5f4a67444 100644 --- a/main/tasks.py +++ b/main/tasks.py @@ -11,5 +11,5 @@ def run_cleartokens(): try: call_command("cleartokens") log.info("Successfully ran cleartokens management command.") - except Exception as e: # noqa: BLE001 - log.exception("Error running cleartokens: %s", e) + except Exception as e: + log.exception("Error running cleartokens") From a98df6bd2cbd90dd5acc2af4cbf61de88f8a45bb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 21 Jan 2026 15:34:45 +0000 Subject: [PATCH 6/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- main/tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/tasks.py b/main/tasks.py index a5f4a67444..f461dd988c 100644 --- a/main/tasks.py +++ b/main/tasks.py @@ -11,5 +11,5 @@ def run_cleartokens(): try: call_command("cleartokens") log.info("Successfully ran cleartokens management command.") - except Exception as e: + except Exception: log.exception("Error running cleartokens")