From ce8c0b18fd9e185e0d9d4b8a54f75edb4955b70e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20S=C3=B8ndergaard?= Date: Sun, 15 Dec 2024 20:52:41 +0100 Subject: [PATCH] Add job id to run and status output --- src/gwf/backends/base.py | 3 +++ src/gwf/plugins/status.py | 15 +++++++++++---- src/gwf/scheduling.py | 11 ++++++++++- tests/plugins/test_run.py | 12 ++++++------ 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/gwf/backends/base.py b/src/gwf/backends/base.py index c278ec30..44f2243f 100644 --- a/src/gwf/backends/base.py +++ b/src/gwf/backends/base.py @@ -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]) diff --git a/src/gwf/plugins/status.py b/src/gwf/plugins/status.py index 38d7871c..99415fb7 100644 --- a/src/gwf/plugins/status.py +++ b/src/gwf/plugins/status.py @@ -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 @@ -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) diff --git a/src/gwf/scheduling.py b/src/gwf/scheduling.py index fcd05951..22c75511 100644 --- a/src/gwf/scheduling.py +++ b/src/gwf/scheduling.py @@ -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"): @@ -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, diff --git a/tests/plugins/test_run.py b/tests/plugins/test_run.py index b3f0a797..816aa6f4 100644 --- a/tests/plugins/test_run.py +++ b/tests/plugins/test_run.py @@ -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"]) @@ -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