diff --git a/posthog/tasks/test/test_warehouse.py b/posthog/tasks/test/test_warehouse.py index a665d8bd95616..5c131470075b3 100644 --- a/posthog/tasks/test/test_warehouse.py +++ b/posthog/tasks/test/test_warehouse.py @@ -4,6 +4,7 @@ check_synced_row_limits_of_team, capture_workspace_rows_synced_by_team, validate_data_warehouse_table_columns, + capture_external_data_rows_synced, ) from posthog.warehouse.models import ExternalDataSource, ExternalDataJob from freezegun import freeze_time @@ -171,3 +172,27 @@ def test_validate_data_warehouse_table_columns(self, mock_get_ph_client: MagicMo assert table.columns.get("some_columns").get("valid") is True mock_ph_client.capture.assert_called_once() mock_ph_client.shutdown.assert_called_once() + + @patch("posthog.tasks.warehouse.capture_workspace_rows_synced_by_team.delay") + def test_capture_external_data_rows_synced(self, mock_capture_workspace_rows_synced_by_team: MagicMock) -> None: + ExternalDataSource.objects.create( + source_id="test_id", + connection_id="fake connectino_id", + destination_id="fake destination_id", + team=self.team, + status="Running", + source_type="Stripe", + ) + + ExternalDataSource.objects.create( + source_id="another_id", + connection_id="fake connectino_id", + destination_id="fake destination_id", + team=self.team, + status="Running", + source_type="Stripe", + ) + + capture_external_data_rows_synced() + + assert mock_capture_workspace_rows_synced_by_team.call_count == 1 diff --git a/posthog/tasks/warehouse.py b/posthog/tasks/warehouse.py index 69970ff9d558d..45672afa3506f 100644 --- a/posthog/tasks/warehouse.py +++ b/posthog/tasks/warehouse.py @@ -23,9 +23,11 @@ def capture_external_data_rows_synced() -> None: # the teams that are not demo and not internal metrics of existing sources - team_ids = ExternalDataSource.objects.filter( - ~Q(team__is_demo=True) & ~Q(team__organization__for_internal_metrics=True) - ).values_list("team", flat=True) + team_ids = ( + ExternalDataSource.objects.filter(~Q(team__is_demo=True) & ~Q(team__organization__for_internal_metrics=True)) + .values_list("team", flat=True) + .distinct() + ) for team_id in team_ids: capture_workspace_rows_synced_by_team.delay(team_id)