feat(tasks): add periodic task to remove old jobs with enhanced logging and context handling

This commit is contained in:
2025-07-09 20:13:20 +05:00
parent 35384ef049
commit ff897ee2ab

View File

@ -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}")