Skip to content

Commit 3b0b05a

Browse files
authored
Fix retries for upload (#21)
* Fix retries for upload * fix lint
1 parent 5d8dc92 commit 3b0b05a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

edge_addons_api/client.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class Options:
2222
client_id: str
2323
client_secret: str
2424
access_token_url: str
25+
retry_count: int = 10
26+
sleep_seconds: int = 3
2527

2628

2729
class Client:
@@ -92,15 +94,16 @@ def _check_upload(
9294
self,
9395
operation_id,
9496
access_token: str,
95-
retry_count: int = 5,
96-
sleep_seconds: int = 3,
9797
) -> str:
9898
logger.debug("Checking upload")
9999

100100
upload_status = ""
101101
attempts = 0
102102

103-
while upload_status != ResponseStatus.SUCCEEDED and attempts < retry_count:
103+
while (
104+
upload_status != ResponseStatus.SUCCEEDED
105+
and attempts < self.options.retry_count
106+
):
104107
response = requests.get(
105108
self._status_endpoint(operation_id),
106109
headers={
@@ -121,7 +124,8 @@ def _check_upload(
121124
response_json["errors"],
122125
)
123126
elif upload_status == ResponseStatus.IN_PROGRESS:
124-
time.sleep(sleep_seconds)
127+
time.sleep(self.options.sleep_seconds)
128+
attempts += 1
125129

126130
return upload_status
127131

0 commit comments

Comments
 (0)