Skip to content

Commit

Permalink
Add job id to run and status output
Browse files Browse the repository at this point in the history
  • Loading branch information
dansondergaard committed Dec 15, 2024
1 parent 914c604 commit ce8c0b1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/gwf/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ def submit(self, target, dependencies):
self._tracked_jobs[target.name] = job_id
self._job_states[job_id] = BackendStatus.SUBMITTED

def get_tracked_id(self, target):
return self._tracked_jobs[target.name]

def cancel(self, target):
try:
self.ops.cancel_job(self._tracked_jobs[target.name])
Expand Down
15 changes: 11 additions & 4 deletions src/gwf/plugins/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,30 @@ def _key_target_order(item):
return t.order


def print_table(target_states):
def print_table(target_states, backend):
name_col_width = (
max((len(target.name) for target in target_states.values()), default=0) + 4
)
format_str = "{symbol} {name:<{name_col_width}} {status}"
format_str = "{symbol} {name:<{name_col_width}} {status} (id: {tracked_id})"
for target, status in sorted(target_states.items(), key=_key_target_order):
color, symbol = _STATUS_VISUALS[status]

if hasattr(backend, "get_tracked_id"):
tracked_id = backend.get_tracked_id(target)
else:
tracked_id = "none"

line = format_str.format(
symbol=symbol,
name=target.name,
status=status.name.lower(),
name_col_width=name_col_width,
tracked_id=tracked_id,
)
click.secho(line, fg=color)


def print_summary(target_states):
def print_summary(target_states, backend):
status_counts = Counter(status for status in target_states.values())
_, max_count = status_counts.most_common()[0]
count_width = len(str(max_count)) + 4
Expand Down Expand Up @@ -135,4 +142,4 @@ def status(ctx, status, endpoints, format, targets):
target_states = {k: v for k, v in target_states.items() if k in matches}

printer = FORMATS[format]
printer(target_states)
printer(target_states, backend)
11 changes: 10 additions & 1 deletion src/gwf/scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def submit_backend(target, dependencies, backend, spec_hashes):
injection of option defaults.
"""

logger.info("Submitting target %s", target)
# logger.info("Submitting target %s", target)

new_options = {}
if hasattr(backend, "target_defaults"):
Expand All @@ -162,6 +162,15 @@ def submit_backend(target, dependencies, backend, spec_hashes):
backend.submit(target, dependencies)
spec_hashes.update(target)

if hasattr(backend, "get_tracked_id"):
logger.info(
"Submitted target %s (id: %s)",
target,
backend.get_tracked_id(target),
)
else:
logger.info("Submitted target %s", target)


def submit_workflow(
endpoints,
Expand Down
12 changes: 6 additions & 6 deletions tests/plugins/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ def test_run_submits_targets(cli_runner, local_backend, linear_workflow):
Path("a.txt").touch()

result = cli_runner.invoke(main, ["run"])
assert "Submitting target Target1" in result.output
assert "Submitting target Target2" in result.output
assert "Submitting target Target3" in result.output
assert "Submitted target Target1" in result.output
assert "Submitted target Target2" in result.output
assert "Submitted target Target3" in result.output

for _ in range(30):
result = cli_runner.invoke(main, ["status", "-s", "shouldrun"])
Expand All @@ -33,6 +33,6 @@ def test_run_partially_submits_targets(cli_runner, local_backend, linear_workflo
Path("a.txt").touch()

result = cli_runner.invoke(main, ["run", "Target2"])
assert "Submitting target Target1" in result.output
assert "Submitting target Target2" in result.output
assert "Submitting target Target3" not in result.output
assert "Submitted target Target1" in result.output
assert "Submitted target Target2" in result.output
assert "Submitted target Target3" not in result.output

0 comments on commit ce8c0b1

Please sign in to comment.