Skip to content

Commit

Permalink
Use status to determine exit condition
Browse files Browse the repository at this point in the history
As the result object of a task can now be present while the task is
running we need to use the status to wait for task completion.
  • Loading branch information
cjh1 committed Sep 26, 2024
1 parent c0a24bc commit 3bac936
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/sfapi_client/_async/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ async def _wait_for_task(self, task_id) -> str:
json_response = r.json()
task = Task.model_validate(json_response)

if task.status.lower() in ["error", "failed"]:
status = task.status.lower()
if status in ["error", "failed"]:
raise SfApiError(task.result)

if task.result is None:
if status not in ["completed", "cancelled"]:
await _ASYNC_SLEEP(1)
continue

Expand Down
5 changes: 3 additions & 2 deletions src/sfapi_client/_sync/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ def _wait_for_task(self, task_id) -> str:
json_response = r.json()
task = Task.model_validate(json_response)

if task.status.lower() in ["error", "failed"]:
status = task.status.lower()
if status in ["error", "failed"]:
raise SfApiError(task.result)

if task.result is None:
if status not in ["completed", "cancelled"]:
_SLEEP(1)
continue

Expand Down

0 comments on commit 3bac936

Please sign in to comment.