Skip to content

Commit 88e313b

Browse files
author
T.J. Bay
committed
Update wait_until_finished to properly detect final workflow status.
1 parent 402c69c commit 88e313b

1 file changed

Lines changed: 24 additions & 13 deletions

File tree

alpine/workfile.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,8 @@ def download_results(self, workflow_id, process_id):
404404
"""
405405
Downloads a workflow run result.
406406
407-
:param str workflow_id: ID of the workflow.
408-
:param ste process_id: ID of a particular workflow run.
407+
:param int workflow_id: ID of the workflow.
408+
:param str process_id: ID of a particular workflow run.
409409
:return: JSON object of workflow results.
410410
:rtype: dict
411411
:exception WorkspaceNotFoundException: The workspace does not exist.
@@ -459,13 +459,14 @@ def stop(self, process_id):
459459
raise StopFlowFailureException("Stopping the workflow failed with status {0}: {1}"
460460
.format(response.status_code, response.reason))
461461

462-
def wait_until_finished(self, process_id, verbose=False, query_time=10, timeout=3600):
462+
def wait_until_finished(self, workflow_id, process_id, verbose=False, query_time=10, timeout=3600):
463463
"""
464464
Waits for a running workflow to finish.
465465
466-
:param str process_id: Process ID of the workflow.
466+
:param int workflow_id: ID of a particular workflow run.
467+
:param str process_id: ID of a particular workflow run.
467468
:param bool verbose: Optionally print approximate run time.
468-
:param float query_time: Number of seconds between status queries.
469+
:param float query_time: Number of seconds between status queries. Minimum of 1 second.
469470
:param float timeout: Amount of time in seconds to wait for workflow to finish. Will stop if exceeded.
470471
:return: Workflow run status.
471472
:rtype: str
@@ -474,17 +475,20 @@ def wait_until_finished(self, process_id, verbose=False, query_time=10, timeout=
474475
475476
Example::
476477
477-
>>> session.workfile.process.wait_until_finished(process_id = process_id)
478+
>>> session.workfile.process.wait_until_finished(workflow_id = workflow_id, process_id = process_id)
478479
479480
"""
481+
query_time = max(1, query_time)
480482

481483
start = time.time()
482-
self.logger.debug("Waiting for process ID: <{0}> to complete...".format(process_id))
483-
wait_count = 0
484484

485+
self.logger.debug("Waiting for process ID: {0} to complete...".format(process_id))
486+
487+
# workflow_status = self.query_status2(workflow_id, process_id)
485488
workflow_status = self.query_status(process_id)
489+
486490
while workflow_status == "WORKING": # loop while waiting for workflow to complete
487-
wait_count += 1
491+
488492
wait_total = time.time() - start
489493

490494
if wait_total >= timeout:
@@ -494,11 +498,18 @@ def wait_until_finished(self, process_id, verbose=False, query_time=10, timeout=
494498
" It now has status '{2}'.".format(process_id, timeout, stop_status))
495499

496500
if verbose:
497-
print("\rWorkflow in progress for ~{0:.2f} seconds.".format(wait_total)),
501+
print("\rWorkflow in progress for ~{0:.1f} seconds.".format(wait_total)),
498502

499503
time.sleep(query_time)
500504

501-
if workflow_status == "FAILED":
502-
raise RunFlowFailureException("The workflow with process ID: <{0}> failed.".format(process_id))
503505
workflow_status = self.query_status(process_id)
504-
return workflow_status
506+
507+
if verbose:
508+
print("")
509+
510+
# If workflow is finished - find the final status, otherwise return status in progress.
511+
time.sleep(1)
512+
final_results = self.download_results(workflow_id, process_id)
513+
status = self.get_metadata(final_results)['status']
514+
515+
return status

0 commit comments

Comments
 (0)