Skip to content

Commit

Permalink
🐛 tweak default async config to avoid timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
ianardee committed Dec 14, 2023
1 parent ea1af30 commit 4daeb5c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions docs/extras/code_samples/default_async.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ job_id = json_response_enqueue["job"]["id"]

url_parse_queued = f"https://api.mindee.net/v1/products/{account}/{endpoint}/v{version}/documents/queue/{job_id}"
sleep(4)
response_parse = requests.get(url_parse_queued, headers=headers)
tries = 1
while tries < 10:
tries = 0
job_status = ""
while tries < 30:
response_parse = requests.get(url_parse_queued, headers=headers)
if not response_parse.ok:
raise RuntimeError(json_response_enqueue["api_request"]["error"])

response_parse = requests.get(url_parse_queued, headers=headers)
json_response_parse = response_parse.json()
if json_response_parse["job"]["status"] == "completed":
job_status = json_response_parse["job"]["status"]
if job_status == "completed":
break
else:
print(json_response_parse["job"])

tries += 1
sleep(2)

if json_response_parse["job"]["status"] != "completed":
if job_status != "completed":
raise RuntimeError(f"Async parsing timed out after {tries} tries")

print(json.dumps(json_response_parse["document"], indent=2))
6 changes: 3 additions & 3 deletions mindee/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ def enqueue_and_parse(
page_options: Optional[PageOptions] = None,
cropper: bool = False,
endpoint: Optional[Endpoint] = None,
initial_delay_sec: float = 6,
delay_sec: float = 3,
max_retries: int = 10,
initial_delay_sec: float = 4,
delay_sec: float = 2,
max_retries: int = 30,
) -> AsyncPredictResponse:
"""
Enqueues to an asynchronous endpoint and automatically polls for a response.
Expand Down

0 comments on commit 4daeb5c

Please sign in to comment.