mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-07-13 20:45:48 +00:00
refactor(tasks): update job scheduling frequency and reduce max hours for old job removal 🔨
This commit is contained in:
10
api/tasks.py
10
api/tasks.py
@ -18,7 +18,7 @@ logger = logging.getLogger(__name__)
|
|||||||
env.read_env(os.path.join(BASE_DIR, ".env"))
|
env.read_env(os.path.join(BASE_DIR, ".env"))
|
||||||
|
|
||||||
|
|
||||||
@app.periodic(cron="0 4 * * *")
|
@app.periodic(cron="0 * * * *") # every 1 hour
|
||||||
@app.task(
|
@app.task(
|
||||||
queueing_lock="remove_old_jobs",
|
queueing_lock="remove_old_jobs",
|
||||||
pass_context=True,
|
pass_context=True,
|
||||||
@ -28,19 +28,13 @@ async def remove_old_jobs(context, timestamp):
|
|||||||
return await builtin_tasks.remove_old_jobs(
|
return await builtin_tasks.remove_old_jobs(
|
||||||
context,
|
context,
|
||||||
queue="heavy_tasks",
|
queue="heavy_tasks",
|
||||||
max_hours=24,
|
max_hours=1,
|
||||||
remove_failed=True,
|
remove_failed=True,
|
||||||
remove_cancelled=True,
|
remove_cancelled=True,
|
||||||
remove_aborted=True,
|
remove_aborted=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.task
|
|
||||||
def add(x, y):
|
|
||||||
logger.info(f"Executing test background task with {x} and {y}")
|
|
||||||
return x + y
|
|
||||||
|
|
||||||
|
|
||||||
@app.periodic(
|
@app.periodic(
|
||||||
cron="0 0 */28 * *", queue="heavy_tasks", periodic_id="deactivate_expired_devices"
|
cron="0 0 */28 * *", queue="heavy_tasks", periodic_id="deactivate_expired_devices"
|
||||||
) # type: ignore
|
) # type: ignore
|
||||||
|
@ -31,7 +31,6 @@ from typing import cast, Dict, Any
|
|||||||
from django.core.mail import send_mail
|
from django.core.mail import send_mail
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from api.notifications import send_otp
|
from api.notifications import send_otp
|
||||||
from .tasks import add
|
|
||||||
from .utils import check_person_api_verification
|
from .utils import check_person_api_verification
|
||||||
|
|
||||||
# local apps import
|
# local apps import
|
||||||
@ -60,7 +59,6 @@ class ErrorMessages:
|
|||||||
|
|
||||||
@api_view(["GET"])
|
@api_view(["GET"])
|
||||||
def healthcheck(request):
|
def healthcheck(request):
|
||||||
add.defer(1, 2)
|
|
||||||
return Response({"status": "Good"}, status=status.HTTP_200_OK)
|
return Response({"status": "Good"}, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user