-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
push embedding generation onto its own queue
- Loading branch information
1 parent
5aa3681
commit dba20b4
Showing
4 changed files
with
27 additions
and
16 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
posthog/tasks/ee/session_recordings/ai/generate_embeddings.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from typing import List, Any | ||
|
||
from posthog.models import Team | ||
|
||
|
||
# stub - will be introduced in https://github.com/PostHog/posthog/pull/20046 | ||
def generate_recording_embedding(session_id: str, team_id: int) -> None: | ||
pass | ||
|
||
|
||
# stub - will be introduced in https://github.com/PostHog/posthog/pull/20046 | ||
def fetch_recordings_without_embeddings(team: Team) -> List[Any]: | ||
return [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,24 @@ | ||
from datetime import timedelta | ||
|
||
import structlog | ||
from celery import shared_task | ||
from django.utils import timezone | ||
|
||
from posthog.session_recordings.models.session_recording import SessionRecording | ||
from posthog.tasks.ee.session_recordings.ai.generate_embeddings import ( | ||
fetch_recordings_without_embeddings, | ||
generate_recording_embedding, | ||
) | ||
from posthog.tasks.utils import CeleryQueue | ||
|
||
logger = structlog.get_logger(__name__) | ||
|
||
|
||
@shared_task(ignore_result=True) | ||
def embed_single_recording(id: str, team_id: int) -> None: | ||
_ = SessionRecording.objects.get(id=id, team_id=team_id) | ||
# TODO: do the embedding | ||
@shared_task(ignore_result=True, queue=CeleryQueue.SESSION_REPLAY_EMBEDDINGS.value) | ||
def embed_single_recording(session_id: str, team_id: int) -> None: | ||
generate_recording_embedding(session_id, team_id) | ||
|
||
|
||
@shared_task(ignore_result=True) | ||
def generate_recording_embeddings() -> None: | ||
one_day_old = timezone.now() - timedelta(hours=24) | ||
one_week_old = timezone.now() - timedelta(days=7) | ||
finished_recordings = SessionRecording.objects.filter( | ||
created_at__lte=one_week_old, created_at__gte=one_day_old, object_storage_path=None | ||
) | ||
|
||
logger.info("Embedding finished recordings", count=finished_recordings.count()) | ||
recordings = fetch_recordings_without_embeddings() | ||
|
||
for recording in finished_recordings: | ||
for recording in recordings: | ||
# push each embedding task to a separate queue | ||
embed_single_recording.delay(recording.session_id, recording.team_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters