Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Cloud diffs in progress #510

Merged
merged 3 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion data_diff/cloud/datafold_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import pydantic
import requests

from ..utils import getLogger

logger = getLogger(__name__)

Self = TypeVar("Self", bound=pydantic.BaseModel)

Expand Down Expand Up @@ -216,11 +219,12 @@ def poll_data_diff_results(self, diff_id: int) -> TCloudApiDataDiffSummaryResult
summary_results = None
start_time = time.monotonic()
sleep_interval = 5 # starts at 5 sec
max_sleep_interval = 60
max_sleep_interval = 30
max_wait_time = 300

diff_url = f"{self.host}/datadiffs/{diff_id}/overview"
while not summary_results:
logger.debug(f"Polling: {diff_url}")
response = self.make_get_request(url=f"api/v1/datadiffs/{diff_id}/summary_results")
response_json = response.json()
if response_json["status"] == "success":
Expand Down
7 changes: 4 additions & 3 deletions data_diff/dbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def dbt_diff(
"Datasource ID not found, include it as a dbt variable in the dbt_project.yml. "
"\nvars:\n data_diff:\n datasource_id: 1234"
)
rich.print("[green][bold]\nDiffs in progress...[/][/]\n")

else:
dbt_parser.set_connection()
Expand Down Expand Up @@ -288,14 +289,14 @@ def _cloud_diff(diff_vars: DiffVars, datasource_id: int, api: DatafoldAPI) -> No
diff_url = None
try:
diff_id = api.create_data_diff(payload=payload)
diff_url = f"{api.host}/datadiffs/{diff_id}/overview"
rich.print(f"{diff_vars.dev_path[2]}: {diff_url}")

if diff_id is None:
raise Exception(f"Api response did not contain a diff_id")

diff_results = api.poll_data_diff_results(diff_id)

diff_url = f"{api.host}/datadiffs/{diff_id}/overview"

rows_added_count = diff_results.pks.exclusives[1]
rows_removed_count = diff_results.pks.exclusives[0]

Expand Down Expand Up @@ -352,4 +353,4 @@ def _cloud_diff(diff_vars: DiffVars, datasource_id: int, api: DatafoldAPI) -> No


def _diff_output_base(dev_path: str, prod_path: str) -> str:
return f"[green]{prod_path} <> {dev_path}[/] \n"
return f"\n[green]{prod_path} <> {dev_path}[/] \n"
6 changes: 3 additions & 3 deletions tests/test_dbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ def test_cloud_diff(self, mock_api, mock_os_environ, mock_print):
_cloud_diff(diff_vars, expected_datasource_id, api=mock_api)

mock_api.create_data_diff.assert_called_once()
mock_print.assert_called_once()
self.assertEqual(mock_print.call_count, 2)

payload = mock_api.create_data_diff.call_args[1]["payload"]
self.assertEqual(payload.data_source1_id, expected_datasource_id)
Expand Down Expand Up @@ -541,7 +541,7 @@ def test_diff_is_cloud(
mock_initialize_api.assert_called_once()
mock_cloud_diff.assert_called_once_with(expected_diff_vars, 1, api)
mock_local_diff.assert_not_called()
mock_print.assert_not_called()
mock_print.assert_called_once()

@patch("data_diff.dbt._initialize_api")
@patch("data_diff.dbt._get_diff_vars")
Expand Down Expand Up @@ -722,7 +722,7 @@ def test_diff_is_cloud_no_pks(
mock_dbt_parser_inst.set_connection.assert_not_called()
mock_cloud_diff.assert_not_called()
mock_local_diff.assert_not_called()
self.assertEqual(mock_print.call_count, 1)
self.assertEqual(mock_print.call_count, 2)

@patch("data_diff.dbt._get_diff_vars")
@patch("data_diff.dbt._local_diff")
Expand Down