Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite committed Jan 17, 2024
1 parent 035888c commit 0faf18b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
5 changes: 4 additions & 1 deletion ee/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 1 addition & 1 deletion ee/tasks/subscriptions/subscription_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions ee/tasks/test/subscriptions/test_subscriptions_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions posthog/tasks/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from prometheus_client import Counter, Histogram

from posthog import settings
from posthog.celery import app
from posthog.models import ExportedAsset

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0faf18b

Please sign in to comment.