Skip to content

Commit e6cf3cc

Browse files
committed
fix: Allow multiple tries for PowerBI params update
1 parent 3247802 commit e6cf3cc

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Babylon/commands/powerbi/dataset/services/powerbi_params_svc.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
from time import sleep
23

34
from Babylon.utils.request import oauth_request
45

@@ -21,14 +22,21 @@ def get(self, workspace_id: str, dataset_id: str):
2122
output_data = response.json().get("value")
2223
return output_data
2324

24-
def update(self, workspace_id: str, params: list[tuple[str, str]], dataset_id: str):
25+
def update(self, workspace_id: str, params: list[tuple[str, str]], dataset_id: str, max_retries: int = 2):
2526
workspace_id = workspace_id or self.state["powerbi"]["workspace"]["id"]
2627
# Preparing parameter data
2728
details = {"updateDetails": [{"name": param.get("id"), "newValue": param.get('value')} for param in params]}
2829
update_url = (f"https://api.powerbi.com/v1.0/myorg/groups/{workspace_id}"
2930
f"/datasets/{dataset_id}/Default.UpdateParameters")
31+
tries = 0
3032
response = oauth_request(update_url, self.powerbi_token, json=details, type="POST")
33+
while response is None and tries < max_retries:
34+
tries += 1
35+
sleep(1)
36+
response = oauth_request(update_url, self.powerbi_token, json=details, type="POST")
3137
if response is None:
32-
logger.info(f"[powerbi] failled to update dataset with id: {dataset_id}")
38+
logger.info(f"[powerbi] failled to update dataset with id: {dataset_id}"
39+
f"\n parameters: {details}"
40+
f"\n tries: {1 + tries}")
3341
return None
34-
logger.info("[powerbi] parameters successfully updated")
42+
logger.info(f"[powerbi] parameters successfully updated (try #{tries})")

0 commit comments

Comments
 (0)