Skip to content

Commit 2a00f77

Browse files
committed
Implement hybrid sync and async request mode
Add wait argument to Prefer header Solves #1331
1 parent f8cbc36 commit 2a00f77

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

TM1py/Services/RestService.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ def _execute_async_request(
371371
"""
372372
# Add async header
373373
http_headers = kwargs.get("headers", dict())
374-
http_headers.update({"Prefer": "respond-async"})
374+
http_headers.update({"Prefer": "respond-async,wait=55"})
375375
kwargs["headers"] = http_headers
376376

377377
# Make initial request
@@ -386,17 +386,19 @@ def _execute_async_request(
386386

387387
self.verify_response(response=response)
388388

389+
if response.status_code != 202:
390+
return response
391+
389392
# Handle async response
390-
if "Location" in response.headers and "'" in response.headers.get("Location", ""):
391-
async_id = response.headers.get("Location").split("'")[1]
392-
if return_async_id:
393-
return async_id
393+
async_id = response.headers.get("Location").split("'")[1]
394+
if return_async_id:
395+
return async_id
394396

395-
# Poll for async result
396-
response = self._poll_async_response(async_id, timeout, cancel_at_timeout, method, url)
397+
# Poll for async result
398+
response = self._poll_async_response(async_id, timeout, cancel_at_timeout, method, url)
397399

398-
# Transform response if needed
399-
response = self._transform_async_response(response)
400+
# Transform response if needed
401+
response = self._transform_async_response(response)
400402

401403
return response
402404

0 commit comments

Comments
 (0)