: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(experiments): register the recalculation activity task queue (#118778)
Rodrigo Iloroa1786eba182c
diff --git a/posthog/management/commands/start_temporal_worker.py b/posthog/management/commands/start_temporal_worker.pyindex 443d2e801365..2d0b4a285e63 100644--- a/posthog/management/commands/start_temporal_worker.py+++ b/posthog/management/commands/start_temporal_worker.py@@ -223,6 +223,7 @@ from products.experiments.backend.temporal import (EXPERIMENT_CANARY_WORKFLOWS,EXPERIMENT_ENROLLMENT_CENSUS_ACTIVITIES,EXPERIMENT_ENROLLMENT_CENSUS_WORKFLOWS,+ EXPERIMENT_RECALCULATION_ACTIVITY_QUEUE_ACTIVITIES,EXPERIMENT_SCHEDULED_RECALCULATION_ACTIVITIES,EXPERIMENT_SCHEDULED_RECALCULATION_WORKFLOWS,WORKFLOWS as EXPERIMENTS_RECALCULATION_WORKFLOWS,@@ -459,6 +460,13 @@ _task_queue_specs = [EXPERIMENTS_RECALCULATION_WORKFLOWS,EXPERIMENTS_RECALCULATION_ACTIVITIES,),+ # The calc activity gets its own queue so that a worker with a fixed slot count caps how many+ # recalculation ClickHouse queries run at the same time.+ (+ settings.EXPERIMENTS_RECALCULATION_ACTIVITY_TASK_QUEUE,+ [],+ EXPERIMENT_RECALCULATION_ACTIVITY_QUEUE_ACTIVITIES,+ ),(settings.HEALTH_CHECK_TASK_QUEUE,HEALTH_CHECK_WORKFLOWS,diff --git a/posthog/settings/temporal.py b/posthog/settings/temporal.pyindex d9de917ef9c7..f89cd60f24d7 100644--- a/posthog/settings/temporal.py+++ b/posthog/settings/temporal.py@@ -336,6 +336,9 @@ SIGNUP_ENRICHMENT_TASK_QUEUE = _set_temporal_task_queue(# workflow execution timeout closes them.CANVAS_BUILD_TASK_QUEUE = _set_temporal_task_queue(os.getenv("CANVAS_BUILD_TASK_QUEUE", "general-purpose-task-queue"))EXPERIMENTS_RECALCULATION_TASK_QUEUE = _set_temporal_task_queue("experiments-recalculation-task-queue")+EXPERIMENTS_RECALCULATION_ACTIVITY_TASK_QUEUE = _set_temporal_task_queue(+ "experiments-recalculation-activity-task-queue"+)HEALTH_CHECK_TASK_QUEUE = _set_temporal_task_queue("health-check-task-queue")DUCKLAKE_TASK_QUEUE = _set_temporal_task_queue("ducklake-task-queue")TASKS_TASK_QUEUE = _set_temporal_task_queue("tasks-task-queue")diff --git a/products/experiments/backend/temporal/__init__.py b/products/experiments/backend/temporal/__init__.pyindex 6dd76a9035b9..f9291da62de8 100644--- a/products/experiments/backend/temporal/__init__.py+++ b/products/experiments/backend/temporal/__init__.py@@ -46,6 +46,9 @@ EXPERIMENT_SCHEDULED_RECALCULATION_ACTIVITIES = [check_experiment_exposures,start_scheduled_recalculation,]+EXPERIMENT_RECALCULATION_ACTIVITY_QUEUE_ACTIVITIES = [+ calculate_experiment_metric_for_recalculation,+]WORKFLOWS = [ExperimentMetricsRecalculationWorkflow,@@ -69,6 +72,7 @@ __all__ = ["EXPERIMENT_CANARY_WORKFLOWS","EXPERIMENT_ENROLLMENT_CENSUS_ACTIVITIES","EXPERIMENT_ENROLLMENT_CENSUS_WORKFLOWS",+ "EXPERIMENT_RECALCULATION_ACTIVITY_QUEUE_ACTIVITIES","EXPERIMENT_SCHEDULED_RECALCULATION_ACTIVITIES","EXPERIMENT_SCHEDULED_RECALCULATION_WORKFLOWS","WORKFLOWS",diff --git a/products/experiments/backend/temporal/test_registration.py b/products/experiments/backend/temporal/test_registration.pyindex fbc09153e9fa..db09ace31803 100644--- a/products/experiments/backend/temporal/test_registration.py+++ b/products/experiments/backend/temporal/test_registration.py@@ -1,9 +1,14 @@-from products.experiments.backend.temporal import ACTIVITIES, WORKFLOWS+from products.experiments.backend.temporal import (+ ACTIVITIES,+ EXPERIMENT_RECALCULATION_ACTIVITY_QUEUE_ACTIVITIES,+ WORKFLOWS,+)from products.experiments.backend.temporal.canary_workflow import ExperimentPrecomputeCanaryWorkflowfrom products.experiments.backend.temporal.enrollment_census_activities import run_experiment_enrollment_censusfrom products.experiments.backend.temporal.enrollment_census_workflow import (ExperimentPrecomputeEnrollmentCensusWorkflow,)+from products.experiments.backend.temporal.recalculation_activities import calculate_experiment_metric_for_recalculationfrom products.experiments.backend.temporal.recalculation_workflow import ExperimentMetricsRecalculationWorkflowfrom products.experiments.backend.temporal.scheduled_recalculation_activities import (check_experiment_exposures,@@ -66,3 +71,26 @@ def test_scheduled_workflows_registered_on_general_purpose_queue():assert discover_scheduled_recalculation_candidates in activitiesassert check_experiment_exposures in activitiesassert start_scheduled_recalculation in activities+++def test_calc_activity_registered_on_recalculation_and_activity_queues():+ # Matches specs by content for the same reason as the test above: in test settings every+ # queue name aliases to one value.+ from posthog.management.commands.start_temporal_worker import ( # noqa: PLC0415 — imports every product's temporal modules+ _task_queue_specs,+ )++ recalculation_specs = [+ activities+ for _queue, workflows, activities in _task_queue_specs+ if ExperimentMetricsRecalculationWorkflow in workflows+ ]+ activity_queue_specs = [+ (workflows, activities)+ for _queue, workflows, activities in _task_queue_specs+ if calculate_experiment_metric_for_recalculation in activities and not workflows+ ]+ assert len(recalculation_specs) == 1+ assert calculate_experiment_metric_for_recalculation in recalculation_specs[0]+ assert activity_queue_specs == [([], EXPERIMENT_RECALCULATION_ACTIVITY_QUEUE_ACTIVITIES)]+ assert EXPERIMENT_RECALCULATION_ACTIVITY_QUEUE_ACTIVITIES == [calculate_experiment_metric_for_recalculation]diff --git a/tach.toml b/tach.tomlindex 79fe1ab016e6..40250e39dd27 100644--- a/tach.toml+++ b/tach.toml@@ -1199,6 +1199,7 @@ expose = ["backend\\.temporal\\.EXPERIMENT_CANARY_WORKFLOWS","backend\\.temporal\\.EXPERIMENT_ENROLLMENT_CENSUS_ACTIVITIES","backend\\.temporal\\.EXPERIMENT_ENROLLMENT_CENSUS_WORKFLOWS",+ "backend\\.temporal\\.EXPERIMENT_RECALCULATION_ACTIVITY_QUEUE_ACTIVITIES","backend\\.temporal\\.EXPERIMENT_SCHEDULED_RECALCULATION_ACTIVITIES","backend\\.temporal\\.EXPERIMENT_SCHEDULED_RECALCULATION_WORKFLOWS","backend\\.temporal\\.WORKFLOWS",