Skip to content

Commit 8b9e9db

Browse files
committed
More consistent behavior for --no_wait.
1 parent 68c2caa commit 8b9e9db

1 file changed

Lines changed: 35 additions & 31 deletions

File tree

planemo/galaxy/activity.py

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -251,18 +251,24 @@ def invocation_to_run_response(
251251

252252
ctx.vlog("Waiting for invocation [%s]" % invocation_id)
253253

254-
final_invocation_state, job_state, error_message = wait_for_invocation_and_jobs(
255-
ctx,
256-
invocation_id=invocation_id,
257-
history_id=history_id,
258-
user_gi=user_gi,
259-
no_wait=no_wait,
260-
polling_backoff=polling_backoff,
261-
)
262-
if final_invocation_state not in ("ok", "skipped", "scheduled"):
263-
msg = f"Failed to run workflow [{workflow_id}], at least one job is in [{final_invocation_state}] state."
264-
ctx.vlog(msg)
265-
summarize_history(ctx, user_gi, history_id)
254+
if not no_wait:
255+
final_invocation_state, job_state, error_message = wait_for_invocation_and_jobs(
256+
ctx,
257+
invocation_id=invocation_id,
258+
history_id=history_id,
259+
user_gi=user_gi,
260+
polling_backoff=polling_backoff,
261+
)
262+
263+
if final_invocation_state not in ("ok", "skipped", "scheduled"):
264+
msg = f"Failed to run workflow [{workflow_id}], at least one job is in [{final_invocation_state}] state."
265+
ctx.vlog(msg)
266+
summarize_history(ctx, user_gi, history_id)
267+
268+
else:
269+
final_invocation_state = invocation["state"]
270+
job_state = None
271+
error_message = None
266272

267273
return GalaxyWorkflowRunResponse(
268274
ctx,
@@ -766,7 +772,7 @@ def _history_id(gi, **kwds) -> str:
766772

767773

768774
def wait_for_invocation_and_jobs(
769-
ctx, invocation_id: str, history_id: str, user_gi: GalaxyInstance, no_wait: bool, polling_backoff: int
775+
ctx, invocation_id: str, history_id: str, user_gi: GalaxyInstance, polling_backoff: int
770776
):
771777
ctx.vlog("Waiting for invocation [%s]" % invocation_id)
772778
final_invocation_state = "new"
@@ -784,25 +790,23 @@ def wait_for_invocation_and_jobs(
784790

785791
ctx.vlog(f"Final state of invocation {invocation_id} is [{final_invocation_state}]")
786792

787-
if not no_wait:
788-
job_state = _wait_for_invocation_jobs(ctx, user_gi, invocation_id, polling_backoff)
789-
if job_state not in ("ok", "skipped"):
790-
msg = f"Failed to run workflow, at least one job is in [{job_state}] state."
791-
error_message = msg if not error_message else f"{error_message}. {msg}"
792-
else:
793-
for subworkflow_invocation_id in subworkflow_invocation_ids(user_gi, invocation_id):
794-
final_invocation_state, job_state, error_message = wait_for_invocation_and_jobs(
795-
ctx,
796-
invocation_id=subworkflow_invocation_id,
797-
history_id=history_id,
798-
user_gi=user_gi,
799-
no_wait=no_wait,
800-
polling_backoff=polling_backoff,
801-
)
802-
if final_invocation_state != "scheduled" or job_state not in ("ok", "skipped"):
803-
return final_invocation_state, job_state, error_message
793+
job_state = _wait_for_invocation_jobs(ctx, user_gi, invocation_id, polling_backoff)
794+
if job_state not in ("ok", "skipped"):
795+
msg = f"Failed to run workflow, at least one job is in [{job_state}] state."
796+
error_message = msg if not error_message else f"{error_message}. {msg}"
797+
else:
798+
for subworkflow_invocation_id in subworkflow_invocation_ids(user_gi, invocation_id):
799+
final_invocation_state, job_state, error_message = wait_for_invocation_and_jobs(
800+
ctx,
801+
invocation_id=subworkflow_invocation_id,
802+
history_id=history_id,
803+
user_gi=user_gi,
804+
polling_backoff=polling_backoff,
805+
)
806+
if final_invocation_state != "scheduled" or job_state not in ("ok", "skipped"):
807+
return final_invocation_state, job_state, error_message
804808

805-
ctx.vlog(f"The final state of all jobs and subworkflow invocations for invocation [{invocation_id}] is 'ok'")
809+
ctx.vlog(f"The final state of all jobs and subworkflow invocations for invocation [{invocation_id}] is 'ok'")
806810
return final_invocation_state, job_state, error_message
807811

808812

0 commit comments

Comments
 (0)