Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions src/gridtk/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ def states_callback(ctx, param, value):
return parse_states(value)


def no_jobs_message(
action: str,
*,
default_states: bool = False,
) -> str:
"""Build a helpful message when no jobs match the given filters."""
msg = f"No jobs were {action}."
if default_states:
msg += (
" Note: the default state filter is active."
" Use --state all to include all jobs."
)
return msg


def job_filters(f_py=None, default_states=None):
"""Filter jobs based on the provided function and default states."""
assert callable(f_py) or f_py is None
Expand Down Expand Up @@ -389,10 +404,10 @@ def resubmit(
)
if not jobs:
click.echo(
"No jobs were resubmitted. Note that the default state "
"filtering may have excluded some jobs. If you want to "
"resubmit all jobs, please use the option: "
"gridtk resubmit --state all"
no_jobs_message(
"resubmitted",
default_states=True,
)
)
for job in jobs:
click.echo(f"Resubmitted job {job.id}")
Expand Down Expand Up @@ -507,6 +522,8 @@ def truncate_str(content: str, max_width: int) -> str:
maxheadercolwidths=maxcolwidths,
)
)
else:
click.echo(no_jobs_message("found"))
session.commit()


Expand All @@ -528,6 +545,8 @@ def stop(
jobs = job_manager.stop_jobs(
job_ids=job_ids, states=states, names=names, dependents=dependents
)
if not jobs:
click.echo(no_jobs_message("stopped"))
for job in jobs:
click.echo(f"Stopped job {job.id} with slurm id {job.grid_id}")
session.commit()
Expand All @@ -551,6 +570,8 @@ def delete(
jobs = job_manager.delete_jobs(
job_ids=job_ids, states=states, names=names, dependents=dependents
)
if not jobs:
click.echo(no_jobs_message("deleted"))
for job in jobs:
click.echo(f"Deleted job {job.id} with slurm id {job.grid_id}")
session.commit()
Expand Down Expand Up @@ -581,6 +602,8 @@ def report(
jobs = job_manager.list_jobs(
job_ids=job_ids, states=states, names=names, dependents=dependents
)
if not jobs:
click.echo(no_jobs_message("found"))
for job in jobs:
report_text = ""
report_text += f"Job ID: {job.id}\n"
Expand Down
7 changes: 4 additions & 3 deletions tests/test_gridtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def test_list_jobs(mock_check_output, runner):
# test when there are no jobs
result = runner.invoke(cli, ["list"])
assert_click_runner_result(result)
assert result.output == ""
assert "No jobs were found." in result.output

# test when there are jobs
submit_job_id = 9876543
Expand Down Expand Up @@ -496,8 +496,9 @@ def test_resubmit_no_jobs(mock_check_output, runner):
)
result = runner.invoke(cli, ["resubmit"])
assert_click_runner_result(result)
assert "No jobs were resubmitted" in result.output
assert "gridtk resubmit --state all" in result.output
assert "No jobs were resubmitted." in result.output
assert "default state filter" in result.output
assert "--state all" in result.output


@patch("subprocess.check_output")
Expand Down
Loading