: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
chore(dags): move skip_on_kill_switch to the shared dags module (#91090)
Javier Bahamondesbe764af6070c
diff --git a/posthog/dags/common/__init__.py b/posthog/dags/common/__init__.pyindex 1a498d65df76..8583e24ee8a5 100644--- a/posthog/dags/common/__init__.py+++ b/posthog/dags/common/__init__.py@@ -6,6 +6,7 @@ from .common import (dagster_tags,settings_with_log_comment,skip_if_already_running,+ skip_on_kill_switch,)__all__ = [@@ -15,4 +16,5 @@ __all__ = ["dagster_tags","settings_with_log_comment","skip_if_already_running",+ "skip_on_kill_switch",]diff --git a/posthog/dags/common/common.py b/posthog/dags/common/common.pyindex 31717fe4d9b8..4a88d79a8b9c 100644--- a/posthog/dags/common/common.py+++ b/posthog/dags/common/common.py@@ -2,12 +2,17 @@ from collections.abc import Callablefrom contextlib import suppressfrom datetime import datetime, timedeltafrom functools import wraps-from typing import Optional+from typing import Optional, Unionimport dagsterfrom posthog.clickhouse import query_tagging+from posthog.clickhouse.client.execute import KillSwitchLevel, get_kill_switch_levelfrom posthog.clickhouse.query_tagging import DagsterTags+from posthog.settings import TEST++# What a Dagster schedule function may return.+ScheduleResult = Union[dagster.SkipReason, dagster.RunRequest, None]def dagster_tags(@@ -82,6 +87,23 @@ def check_for_concurrent_runs(return None+def skip_on_kill_switch(+ fn: Callable[[dagster.ScheduleEvaluationContext], ScheduleResult],+) -> Callable[[dagster.ScheduleEvaluationContext], ScheduleResult]:+ """Decorator that skips schedule execution while the ClickHouse kill switch is on."""++ @wraps(fn)+ def wrapper(context: dagster.ScheduleEvaluationContext) -> ScheduleResult:+ if not TEST:+ kill_switch_level = get_kill_switch_level()+ if kill_switch_level != KillSwitchLevel.OFF:+ context.log.info(f"Skipping due to ClickHouse kill switch: {kill_switch_level}")+ return dagster.SkipReason(f"ClickHouse kill switch is enabled ({kill_switch_level})")+ return fn(context)++ return wrapper++def skip_if_already_running(fn: Callable) -> Callable:"""Decorator that skips schedule execution if a previous run is still active.diff --git a/products/web_analytics/dags/web_dimensional_precompute.py b/products/web_analytics/dags/web_dimensional_precompute.pyindex 897e4c1ac9fd..6d43d12d6f09 100644--- a/products/web_analytics/dags/web_dimensional_precompute.py+++ b/products/web_analytics/dags/web_dimensional_precompute.py@@ -28,14 +28,13 @@ import structlogfrom prometheus_client import Counterfrom posthog.cloud_utils import is_cloud-from posthog.dags.common import JobOwners, chunk_ranges+from posthog.dags.common import JobOwners, chunk_ranges, skip_on_kill_switchfrom posthog.models import Teamfrom products.web_analytics.backend.hogql_queries.web_dimensional_precompute import (ensure_web_bounces_dimensional_precomputed,ensure_web_stats_dimensional_precomputed,)-from products.web_analytics.dags.web_preaggregated import skip_on_kill_switchfrom products.web_analytics.dags.web_preaggregated_utils import check_for_concurrent_runslogger = structlog.get_logger(__name__)diff --git a/products/web_analytics/dags/web_preaggregated.py b/products/web_analytics/dags/web_preaggregated.pyindex 02a063601b90..822e9492dcac 100644--- a/products/web_analytics/dags/web_preaggregated.py+++ b/products/web_analytics/dags/web_preaggregated.py@@ -1,8 +1,6 @@import osfrom collections.abc import Callablefrom datetime import UTC, datetime, timedelta-from functools import wraps-from typing import Unionimport dagsterfrom dagster import BackfillPolicy, DailyPartitionsDefinition@@ -11,10 +9,9 @@ from posthog.schema import ProductKeyfrom posthog.clickhouse import query_taggingfrom posthog.clickhouse.client import sync_execute-from posthog.clickhouse.client.execute import KillSwitchLevel, get_kill_switch_levelfrom posthog.clickhouse.cluster import ClickhouseClusterfrom posthog.clickhouse.query_tagging import Feature, tags_context-from posthog.dags.common import JobOwners, dagster_tags+from posthog.dags.common import JobOwners, dagster_tags, skip_on_kill_switchfrom posthog.models.web_preaggregated.sql import (REPLACE_WEB_BOUNCES_V2_STAGING_SQL,REPLACE_WEB_STATS_V2_STAGING_SQL,@@ -38,24 +35,6 @@ from products.web_analytics.dags.web_preaggregated_utils import (web_analytics_retry_policy_def,)-ScheduleResult = Union[dagster.SkipReason, dagster.RunRequest, None]---def skip_on_kill_switch(- fn: Callable[[dagster.ScheduleEvaluationContext], ScheduleResult],-) -> Callable[[dagster.ScheduleEvaluationContext], ScheduleResult]:- @wraps(fn)- def wrapper(context: dagster.ScheduleEvaluationContext) -> ScheduleResult:- if not TEST:- kill_switch_level = get_kill_switch_level()- if kill_switch_level != KillSwitchLevel.OFF:- context.log.info(f"Skipping due to ClickHouse kill switch: {kill_switch_level}")- return dagster.SkipReason(f"ClickHouse kill switch is enabled ({kill_switch_level})")- return fn(context)-- return wrapper--MAX_PARTITIONS_PER_RUN_ENV_VAR = "DAGSTER_WEB_PREAGGREGATED_MAX_PARTITIONS_PER_RUN"max_partitions_per_run = int(os.getenv(MAX_PARTITIONS_PER_RUN_ENV_VAR, 1))backfill_policy_def = BackfillPolicy.multi_run(max_partitions_per_run=max_partitions_per_run)