Skip to content

Commit

Permalink
Add priority flag to vh exec run (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
akx authored Jan 27, 2025
1 parent e9d5cd0 commit cdc6cfb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
7 changes: 7 additions & 0 deletions tests/commands/execution/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,3 +427,10 @@ def test_no_git_adhoc_packaging(logged_in_and_linked, monkeypatch, allow_git_pac
assert "Used git to find" in output
else:
assert "Walked filesystem and found" in output


@pytest.mark.parametrize("val", (0, 7, 42))
def test_priority(run_test_setup, val):
run_test_setup.args.append(f"--priority={val}")
run_test_setup.run()
assert run_test_setup.run_api_mock.last_create_execution_payload["priority"] == val
7 changes: 6 additions & 1 deletion valohai_cli/commands/execution/run/dynamic_run_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def __init__(
runtime_config: Optional[dict] = None,
runtime_config_preset: Optional[str] = None,
ssh: bool = False,
priority: Optional[int] = None,
) -> None:
"""
Initialize the dynamic run command.
Expand Down Expand Up @@ -94,6 +95,7 @@ def __init__(
self.runtime_config = dict(runtime_config or {})
self.runtime_config_preset = runtime_config_preset
self.ssh = ssh
self.priority = priority
super().__init__(
name=sanitize_option_name(step.name.lower()),
callback=self.execute,
Expand Down Expand Up @@ -233,12 +235,15 @@ def _build_payload(self, **kwargs: Any) -> dict:
payload.update(self._optional_item("tags"))
payload.update(self._optional_item("runtime_config"))
payload.update(self._optional_item("runtime_config_preset"))
payload.update(self._optional_item("priority"))

return payload

def _optional_item(self, attribute_name: str) -> dict:
value = getattr(self, attribute_name, None)
return {attribute_name: value} if value else {}
if value in ("", None): # An explicit zero should be included
return {}
return {attribute_name: value}

def _sift_kwargs(self, kwargs: Dict[str, str]) -> Tuple[dict, dict, dict]:
# Sift kwargs into params, options, and inputs
Expand Down
8 changes: 8 additions & 0 deletions valohai_cli/commands/execution/run/frontend_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@
"--autorestart/--no-autorestart",
help="Enable Automatic Restart on Spot Instance Interruption",
)
@click.option(
"--priority",
type=int,
default=None,
help="Priority for the job; higher values mean higher priority.",
)
@click.option(
"--k8s-cpu-min",
help="Kubernetes only. CPU resouce request",
Expand Down Expand Up @@ -182,6 +188,7 @@ def run(
debug_port: int,
debug_key_file: Optional[str],
autorestart: bool,
priority: Optional[int],
k8s_cpu_min: Optional[float],
k8s_memory_min: Optional[int],
k8s_cpu_max: Optional[float],
Expand Down Expand Up @@ -299,6 +306,7 @@ def run(
runtime_config=runtime_config,
runtime_config_preset=k8s_preset,
ssh=ssh,
priority=priority,
)
with rc.make_context(rc.name, list(args), parent=ctx) as child_ctx:
return rc.invoke(child_ctx)
Expand Down

0 comments on commit cdc6cfb

Please sign in to comment.