:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(data-modeling): stamp PostHogScheduleType on v2 dag schedules (#67336)
Jovan Sakovicca8457468c2d
diff --git a/products/data_modeling/backend/management/commands/migrate_teams_to_dag_schedules.py b/products/data_modeling/backend/management/commands/migrate_teams_to_dag_schedules.pyindex 9523fa93eefd..39dbf1da5ed7 100644--- a/products/data_modeling/backend/management/commands/migrate_teams_to_dag_schedules.py+++ b/products/data_modeling/backend/management/commands/migrate_teams_to_dag_schedules.py@@ -15,16 +15,15 @@ from temporalio.client import (SchedulePolicy,ScheduleState,)-from temporalio.common import RetryPolicy, SearchAttributePair, TypedSearchAttributes+from temporalio.common import RetryPolicyfrom posthog.temporal.common.client import sync_connectfrom posthog.temporal.common.schedule import create_schedule, delete_schedule, schedule_exists-from posthog.temporal.common.search_attributes import POSTHOG_DAG_ID_KEY, POSTHOG_ORG_ID_KEY, POSTHOG_TEAM_ID_KEYfrom posthog.temporal.data_modeling.workflows.execute_dag import ExecuteDAGInputsfrom products.data_modeling.backend.models import DAG, Nodefrom products.data_modeling.backend.models.datawarehouse_saved_query import DataWarehouseSavedQuery-from products.data_modeling.backend.schedule import build_schedule_spec+from products.data_modeling.backend.schedule import build_schedule_spec, dag_schedule_search_attributeslogger = structlog.get_logger(__name__)@@ -167,12 +166,10 @@ class Command(BaseCommand):state=ScheduleState(note=f"DAG schedule for team {team.pk}"),policy=SchedulePolicy(overlap=ScheduleOverlapPolicy.SKIP),)- search_attributes = TypedSearchAttributes(- search_attributes=[- SearchAttributePair(key=POSTHOG_TEAM_ID_KEY, value=team.pk),- SearchAttributePair(key=POSTHOG_ORG_ID_KEY, value=str(team.organization_id)),- SearchAttributePair(key=POSTHOG_DAG_ID_KEY, value=str(dag.id)),- ]+ search_attributes = dag_schedule_search_attributes(+ team_id=team.pk,+ organization_id=str(team.organization_id),+ dag_id=str(dag.id),)create_schedule(temporal,diff --git a/products/data_modeling/backend/schedule.py b/products/data_modeling/backend/schedule.pyindex 19061ec50991..2363f05ea6f8 100644--- a/products/data_modeling/backend/schedule.py+++ b/products/data_modeling/backend/schedule.py@@ -18,9 +18,15 @@ from typing import TYPE_CHECKINGfrom asgiref.sync import async_to_syncfrom temporalio.client import ScheduleCalendarSpec, ScheduleListActionStartWorkflow, ScheduleRange, ScheduleSpec+from temporalio.common import SearchAttributePair, TypedSearchAttributesfrom posthog.temporal.common.client import async_connect-from posthog.temporal.common.search_attributes import POSTHOG_DAG_ID_KEY+from posthog.temporal.common.search_attributes import (+ POSTHOG_DAG_ID_KEY,+ POSTHOG_ORG_ID_KEY,+ POSTHOG_SCHEDULE_TYPE_KEY,+ POSTHOG_TEAM_ID_KEY,+)from products.data_modeling.backend.models import Node@@ -32,6 +38,17 @@ if TYPE_CHECKING:DATA_MODELING_EXECUTE_DAG_WORKFLOW = "data-modeling-execute-dag"+def dag_schedule_search_attributes(*, team_id: int, organization_id: str, dag_id: str) -> TypedSearchAttributes:+ return TypedSearchAttributes(+ search_attributes=[+ SearchAttributePair(key=POSTHOG_TEAM_ID_KEY, value=team_id),+ SearchAttributePair(key=POSTHOG_ORG_ID_KEY, value=organization_id),+ SearchAttributePair(key=POSTHOG_DAG_ID_KEY, value=dag_id),+ SearchAttributePair(key=POSTHOG_SCHEDULE_TYPE_KEY, value=DATA_MODELING_EXECUTE_DAG_WORKFLOW),+ ]+ )++@async_to_syncasync def get_v2_scheduled_dag_ids(candidate_dag_ids: Collection[str] | None = None) -> set[str]:"""Return the IDs of DAGs that already have a v2 `data-modeling-execute-dag` Temporal schedule.