From ff897ee2ab3d7b2136ee91919c00b693804e32e1 Mon Sep 17 00:00:00 2001 From: i701 Date: Wed, 9 Jul 2025 20:13:20 +0500 Subject: [PATCH] =?UTF-8?q?feat(tasks):=20add=20periodic=20task=20to=20rem?= =?UTF-8?q?ove=20old=20jobs=20with=20enhanced=20logging=20and=20context=20?= =?UTF-8?q?handling=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/tasks.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/api/tasks.py b/api/tasks.py index 9a7f703..c5d894e 100644 --- a/api/tasks.py +++ b/api/tasks.py @@ -10,6 +10,7 @@ from django.utils import timezone from api.omada import Omada from apibase.env import env, BASE_DIR from procrastinate.contrib.django import app +from procrastinate import builtin_tasks logger = logging.getLogger(__name__) @@ -17,6 +18,23 @@ logger = logging.getLogger(__name__) env.read_env(os.path.join(BASE_DIR, ".env")) +@app.periodic(cron="0 4 * * *") +@app.task( + queueing_lock="remove_old_jobs", + pass_context=True, +) +async def remove_old_jobs(context, timestamp): + logger.info("Running remove_old_jobs task...") + return await builtin_tasks.remove_old_jobs( + context, + queue="heavy_tasks", + max_hours=24, + remove_failed=True, + remove_cancelled=True, + remove_aborted=True, + ) + + @app.task def add(x, y): logger.info(f"Executing test background task with {x} and {y}")