diff --git a/ee/settings.py b/ee/settings.py index f6f6ef43bd9e7..766f1533822c1 100644 --- a/ee/settings.py +++ b/ee/settings.py @@ -68,4 +68,7 @@ # Whether to enable the admin portal. Default false for self-hosted as if not setup properly can pose security issues. ADMIN_PORTAL_ENABLED = get_from_env("ADMIN_PORTAL_ENABLED", DEMO or DEBUG, type_cast=str_to_bool) -ASSET_GENERATION_MAX_TIMEOUT_MINUTES = get_from_env("ASSET_GENERATION_MAX_TIMEOUT_MINUTES", 10.0, type_cast=float) +ASSET_GENERATION_MAX_TIMEOUT_SECONDS = get_from_env("ASSET_GENERATION_MAX_TIMEOUT_SECONDS", 60.0, type_cast=float) +PARALLEL_ASSET_GENERATION_MAX_TIMEOUT_MINUTES = get_from_env( + "PARALLEL_ASSET_GENERATION_MAX_TIMEOUT_MINUTES", 10.0, type_cast=float +) diff --git a/ee/tasks/subscriptions/subscription_utils.py b/ee/tasks/subscriptions/subscription_utils.py index 5df00e4a8ee85..32fb46b9cde13 100644 --- a/ee/tasks/subscriptions/subscription_utils.py +++ b/ee/tasks/subscriptions/subscription_utils.py @@ -60,7 +60,7 @@ def generate_assets( wait_for_parallel_celery_group( parallel_job, - max_timeout=timedelta(minutes=settings.ASSET_GENERATION_MAX_TIMEOUT_MINUTES), + max_timeout=timedelta(seconds=settings.PARALLEL_ASSET_GENERATION_MAX_TIMEOUT_MINUTES), ) return insights, assets diff --git a/ee/tasks/test/subscriptions/test_subscriptions_utils.py b/ee/tasks/test/subscriptions/test_subscriptions_utils.py index 35b2ca350ed8a..c8ff89adcea65 100644 --- a/ee/tasks/test/subscriptions/test_subscriptions_utils.py +++ b/ee/tasks/test/subscriptions/test_subscriptions_utils.py @@ -34,7 +34,7 @@ def setUp(self) -> None: self.subscription = create_subscription(team=self.team, insight=self.insight, created_by=self.user) def test_generate_assets_for_insight(self, mock_export_task: MagicMock, _mock_group: MagicMock) -> None: - with self.settings(ASSET_GENERATION_MAX_TIMEOUT_MINUTES=1): + with self.settings(PARALLEL_ASSET_GENERATION_MAX_TIMEOUT_MINUTES=1): insights, assets = generate_assets(self.subscription) assert insights == [self.insight] @@ -44,7 +44,7 @@ def test_generate_assets_for_insight(self, mock_export_task: MagicMock, _mock_gr def test_generate_assets_for_dashboard(self, mock_export_task: MagicMock, _mock_group: MagicMock) -> None: subscription = create_subscription(team=self.team, dashboard=self.dashboard, created_by=self.user) - with self.settings(ASSET_GENERATION_MAX_TIMEOUT_MINUTES=1): + with self.settings(PARALLEL_ASSET_GENERATION_MAX_TIMEOUT_MINUTES=1): insights, assets = generate_assets(subscription) assert len(insights) == len(self.tiles) @@ -54,7 +54,7 @@ def test_generate_assets_for_dashboard(self, mock_export_task: MagicMock, _mock_ def test_raises_if_missing_resource(self, _mock_export_task: MagicMock, _mock_group: MagicMock) -> None: subscription = create_subscription(team=self.team, created_by=self.user) - with self.settings(ASSET_GENERATION_MAX_TIMEOUT_MINUTES=1), pytest.raises(Exception) as e: + with self.settings(PARALLEL_ASSET_GENERATION_MAX_TIMEOUT_MINUTES=1), pytest.raises(Exception) as e: generate_assets(subscription) assert str(e.value) == "There are no insights to be sent for this Subscription" @@ -68,7 +68,7 @@ def test_excludes_deleted_insights_for_dashboard(self, mock_export_task: MagicMo current_tile.insight.save() subscription = create_subscription(team=self.team, dashboard=self.dashboard, created_by=self.user) - with self.settings(ASSET_GENERATION_MAX_TIMEOUT_MINUTES=1): + with self.settings(PARALLEL_ASSET_GENERATION_MAX_TIMEOUT_MINUTES=1): insights, assets = generate_assets(subscription) assert len(insights) == 1 @@ -90,7 +90,7 @@ def test_cancels_children_if_timed_out(self, _mock_export_task: MagicMock, mock_ mock_running_exports.children = [running_export_task] mock_running_exports.ready = mock_ready - with self.settings(ASSET_GENERATION_MAX_TIMEOUT_MINUTES=0.01), pytest.raises(Exception) as e: + with self.settings(PARALLEL_ASSET_GENERATION_MAX_TIMEOUT_MINUTES=0.01), pytest.raises(Exception) as e: generate_assets(self.subscription) assert str(e.value) == "Timed out waiting for celery task to finish" diff --git a/posthog/tasks/exporter.py b/posthog/tasks/exporter.py index 44a7c86d2c32b..ffec5d5b1142f 100644 --- a/posthog/tasks/exporter.py +++ b/posthog/tasks/exporter.py @@ -2,6 +2,7 @@ from prometheus_client import Counter, Histogram +from posthog import settings from posthog.celery import app from posthog.models import ExportedAsset @@ -40,8 +41,7 @@ retry_backoff=True, acks_late=True, ignore_result=False, - soft_time_limit=30, - time_limit=60, + time_limit=settings.ASSET_GENERATION_MAX_TIMEOUT_SECONDS, ) def export_asset(exported_asset_id: int, limit: Optional[int] = None) -> None: from posthog.tasks.exports import csv_exporter, image_exporter