2023-01-12 09:23:51 +01:00
|
|
|
from datetime import timedelta
|
|
|
|
|
|
|
|
import structlog
|
2024-01-18 14:28:10 +01:00
|
|
|
from celery import shared_task
|
2023-01-12 09:23:51 +01:00
|
|
|
from django.utils import timezone
|
|
|
|
|
2023-09-18 14:35:59 +02:00
|
|
|
from ee.session_recordings.session_recording_extensions import persist_recording
|
|
|
|
from posthog.session_recordings.models.session_recording import SessionRecording
|
2023-01-12 09:23:51 +01:00
|
|
|
|
|
|
|
logger = structlog.get_logger(__name__)
|
|
|
|
|
|
|
|
|
2024-01-18 14:28:10 +01:00
|
|
|
@shared_task(ignore_result=True)
|
2023-01-12 09:23:51 +01:00
|
|
|
def persist_single_recording(id: str, team_id: int) -> None:
|
|
|
|
persist_recording(id, team_id)
|
|
|
|
|
|
|
|
|
2024-01-18 14:28:10 +01:00
|
|
|
@shared_task(ignore_result=True)
|
2023-01-12 09:23:51 +01:00
|
|
|
def persist_finished_recordings() -> None:
|
|
|
|
one_day_old = timezone.now() - timedelta(hours=24)
|
|
|
|
finished_recordings = SessionRecording.objects.filter(created_at__lte=one_day_old, object_storage_path=None)
|
|
|
|
|
|
|
|
logger.info("Persisting finished recordings", count=finished_recordings.count())
|
|
|
|
|
|
|
|
for recording in finished_recordings:
|
|
|
|
persist_single_recording.delay(recording.session_id, recording.team_id)
|