Skip to content

Commit a95640f

Browse files
committed
WIP: Wire up workflow track command
Think we still have some work to do once there are failing jobs.
1 parent af5ced9 commit a95640f

File tree

3 files changed

+13
-33
lines changed

3 files changed

+13
-33
lines changed

planemo/commands/cmd_workflow_track.py

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,22 @@
55
from planemo import options
66
from planemo.cli import command_function
77
from planemo.engine.factory import engine_context
8-
from planemo.galaxy.invocations.progress import WorkflowProgress
8+
from planemo.galaxy.activity import wait_for_invocation_and_jobs
99

1010

1111
@click.command("workflow_track")
1212
@options.invocation_target_options()
1313
@command_function
1414
def cli(ctx, invocation_id, **kwds):
1515
"""Run defined tests against existing workflow invocation."""
16-
with WorkflowProgress() as workflow_progress:
17-
workflow_progress.add_bars()
18-
import time
19-
20-
time.sleep(1)
21-
new_step = {"state": "new"}
22-
scheduled_step = {"state": "scheduled"}
23-
new_steps = [new_step, new_step, new_step]
24-
one_scheduled_steps = [scheduled_step, new_step, new_step]
25-
two_scheduled_steps = [scheduled_step, scheduled_step, new_step]
26-
all_scheduled_steps = [scheduled_step, scheduled_step, scheduled_step]
27-
state_pairs = [
28-
({"state": "new"}, {}),
29-
({"state": "ready", "steps": new_steps}, {}),
30-
({"state": "ready", "steps": one_scheduled_steps}, {"states": {"new": 1}}),
31-
({"state": "ready", "steps": two_scheduled_steps}, {"states": {"new": 2}}),
32-
({"state": "ready", "steps": two_scheduled_steps}, {"states": {"new": 1, "running": 1}}),
33-
({"state": "ready", "steps": two_scheduled_steps}, {"states": {"new": 1, "ok": 1}}),
34-
({"state": "ready", "steps": two_scheduled_steps}, {"states": {"ok": 2}}),
35-
({"state": "scheduled", "steps": all_scheduled_steps}, {"states": {"ok": 2, "new": 3}}),
36-
({"state": "scheduled", "steps": all_scheduled_steps}, {"states": {"ok": 2, "running": 1, "new": 2}}),
37-
({"state": "scheduled", "steps": all_scheduled_steps}, {"states": {"ok": 3, "running": 1, "new": 1}}),
38-
({"state": "scheduled", "steps": all_scheduled_steps}, {"states": {"ok": 4, "running": 1}}),
39-
({"state": "scheduled", "steps": all_scheduled_steps}, {"states": {"ok": 5}}),
40-
]
41-
for invocation, job_states_summary in state_pairs:
42-
workflow_progress.handle_invocation(invocation, job_states_summary)
43-
time.sleep(1)
44-
4516
with engine_context(ctx, engine="external_galaxy", **kwds) as engine, engine.ensure_runnables_served([]) as config:
4617
user_gi = config.user_gi
47-
invocation = user_gi.invocations.show_invocation(invocation_id)
48-
# https://stackoverflow.com/questions/23113494/double-progress-bar-in-python
18+
wait_for_invocation_and_jobs(
19+
ctx,
20+
invocation_id,
21+
history_id=None,
22+
user_gi=user_gi,
23+
polling_backoff=5,
24+
)
4925

5026
ctx.exit(0)

planemo/galaxy/activity.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ def _history_id(gi, **kwds) -> str:
771771

772772

773773
def wait_for_invocation_and_jobs(
774-
ctx, invocation_id: str, history_id: str, user_gi: GalaxyInstance, polling_backoff: int
774+
ctx, invocation_id: str, history_id: Optional[str], user_gi: GalaxyInstance, polling_backoff: int
775775
):
776776
polling_tracker = PollingTrackerImpl(polling_backoff)
777777
invocation_api = BioblendInvocationApi(ctx, user_gi)
@@ -780,6 +780,9 @@ def wait_for_invocation_and_jobs(
780780
ctx, invocation_id, invocation_api, polling_tracker, workflow_progress_display
781781
)
782782
if error_message:
783+
if not history_id:
784+
invocation = invocation_api.get_invocation(invocation_id)
785+
history_id = invocation["history_id"]
783786
summarize_history(ctx, user_gi, history_id)
784787
return final_invocation_state, job_state, error_message
785788

planemo/galaxy/invocations/api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Invocation(TypedDict, total=False):
2626
id: str
2727
state: str
2828
steps: List[InvocationStep]
29+
history_id: Optional[str]
2930

3031

3132
class InvocationJobsSummary(TypedDict, total=False):

0 commit comments

Comments
 (0)