planarian
This commit is contained in:
@@ -512,93 +512,5 @@ def _resize_frame(
|
||||
|
||||
return frame
|
||||
|
||||
# tasks/export_tasks.py
|
||||
|
||||
from celery import shared_task, group
|
||||
from django.utils import timezone
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@shared_task(bind=True)
|
||||
def run_session_exports(self, session_id: str):
|
||||
"""
|
||||
Point d'entrée déclenché par django_celery_beat.
|
||||
Lance en parallèle l'export images et l'export vidéo de la session.
|
||||
"""
|
||||
from cameras.models import ExportSession
|
||||
|
||||
try:
|
||||
session = ExportSession.objects.get(session_id=session_id)
|
||||
except ExportSession.DoesNotExist:
|
||||
logger.error("run_session_exports: session %s introuvable", session_id)
|
||||
return {"status": "error", "message": "Session introuvable"}
|
||||
|
||||
session.status = ExportSession.Status.RUNNING
|
||||
session.save(update_fields=["status"])
|
||||
|
||||
try:
|
||||
# Lancement en parallèle avec group Celery
|
||||
job = group(
|
||||
export_all_images.s(session_id),
|
||||
export_all_videos.s(session_id),
|
||||
).apply_async()
|
||||
|
||||
results = job.get(timeout=7200) # 2h max pour les deux
|
||||
|
||||
session.status = ExportSession.Status.DONE
|
||||
session.exported_at = timezone.now()
|
||||
session.save(update_fields=["status", "exported_at"])
|
||||
|
||||
return {"status": "success", "results": results}
|
||||
|
||||
except Exception as exc:
|
||||
session.status = ExportSession.Status.ERROR
|
||||
session.save(update_fields=["status"])
|
||||
logger.error("run_session_exports [%s]: %s", session_id, exc, exc_info=True)
|
||||
return {"status": "error", "message": str(exc)}
|
||||
|
||||
|
||||
@shared_task(bind=True)
|
||||
def export_all_images(self, session_id: str):
|
||||
"""
|
||||
Export ZIP de toutes les images de la session.
|
||||
"""
|
||||
from cameras.models import ExportSession
|
||||
|
||||
session = ExportSession.objects.get(session_id=session_id)
|
||||
|
||||
return export_images_zip(
|
||||
session.camera_uuid,
|
||||
session.start_ts,
|
||||
session.end_ts,
|
||||
max_zip_size_mb = session.max_zip_size_mb,
|
||||
jpeg_quality = session.jpeg_quality,
|
||||
max_image_width = session.max_image_width,
|
||||
max_image_height = session.max_image_height,
|
||||
)
|
||||
|
||||
|
||||
@shared_task(bind=True)
|
||||
def export_all_videos(self, session_id: str):
|
||||
"""
|
||||
Export MP4 de toutes les vidéos de la session.
|
||||
"""
|
||||
from cameras.models import ExportSession
|
||||
|
||||
session = ExportSession.objects.get(session_id=session_id)
|
||||
|
||||
return export_video_mp4(
|
||||
session.camera_uuid,
|
||||
session.start_ts,
|
||||
session.end_ts,
|
||||
frame_rate = session.frame_rate,
|
||||
max_video_size_mb = session.max_video_size_mb,
|
||||
max_width = session.max_width,
|
||||
max_height = session.max_height,
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user