Skip to content

Commit

Permalink
fix(client): add label for container and cancel by label (#1172)
Browse files Browse the repository at this point in the history
  • Loading branch information
goldenxinxing authored Sep 12, 2022
1 parent bbaa5a7 commit 5a62e1b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions client/starwhale/core/eval/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ def _gen_run_container_cmd(self, typ: str, step: str, task_index: int) -> str:
f"{self._version}-{step}-{task_index}",
"-e",
"DEBUG=1",
"-l",
f"version={self._version}",
]

cmd += [
Expand Down
12 changes: 9 additions & 3 deletions client/starwhale/core/eval/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import json
import typing as t
import subprocess
from abc import ABCMeta, abstractmethod
from http import HTTPStatus
from collections import defaultdict
Expand All @@ -14,7 +15,7 @@
from starwhale.base.uri import URI
from starwhale.utils.fs import move_dir
from starwhale.api._impl import wrapper
from starwhale.base.type import EvalTaskType, InstanceType, JobOperationType
from starwhale.base.type import InstanceType, JobOperationType
from starwhale.base.cloud import CloudRequestMixed
from starwhale.consts.env import SWEnv
from starwhale.utils.http import ignore_error
Expand Down Expand Up @@ -283,8 +284,13 @@ def _do_container_action(
elif action == JobOperationType.RESUME:
cmd += ["unpause"]

# TODO: search container first
cmd += [f"{self.name}-{EvalTaskType.ALL}", f"{self.name}-{EvalTaskType.SINGLE}"]
# search container first
out = subprocess.check_output(
["docker", "ps", "-f", f"label=version={self.store.id}", "-q"]
)
_container = out.decode().strip()

cmd += [_container]
try:
check_call(cmd)
except Exception as e:
Expand Down
3 changes: 2 additions & 1 deletion client/tests/core/test_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ def test_stanalone_remove(self):
/ self.job_name
).exists()

@patch("starwhale.core.eval.model.subprocess.check_output")
@patch("starwhale.core.eval.model.check_call")
def test_stanalone_actions(self, m_call: MagicMock):
def test_stanalone_actions(self, m_call: MagicMock, m_call_output: MagicMock):
uri = URI(f"local/project/self/{URIType.EVALUATION}/{self.job_name}")
job = StandaloneEvaluationJob(uri)

Expand Down
2 changes: 1 addition & 1 deletion client/tests/core/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def test_run(self, m_scheduler: MagicMock, m_call: MagicMock) -> None:

assert ppl_cmd == " ".join(
[
f"docker run --net=host --rm --name {build_version}--0 -e DEBUG=1",
f"docker run --net=host --rm --name {build_version}--0 -e DEBUG=1 -l version={build_version}",
f"-v {job_dir}:/opt/starwhale",
f"-v {sw.rootdir}:/root/.starwhale",
f"-v {sw.object_store_dir}:{sw.object_store_dir}",
Expand Down

0 comments on commit 5a62e1b

Please sign in to comment.