mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-07-12 09:15:49 +00:00
feat(tasks): add periodic task to remove old jobs with enhanced logging and context handling ✨
This commit is contained in:
18
api/tasks.py
18
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}")
|
||||
|
Reference in New Issue
Block a user