mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
queue status: use summary style output for worker status
This commit is contained in:
committed by
Peter Rowlands (변기호)
parent
eeb516e7d3
commit
3130a9a75f
@@ -13,23 +13,29 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CmdQueueStatus(CmdBase):
|
||||
"""Kill exp task in queue."""
|
||||
"""Show queue task and worker status."""
|
||||
|
||||
def run(self):
|
||||
result: List[
|
||||
Mapping[str, Optional[str]]
|
||||
] = self.repo.experiments.celery_queue.status()
|
||||
all_headers = ["Task", "Name", "Created", "Status"]
|
||||
td = TabularData(all_headers)
|
||||
for exp in result:
|
||||
created = format_time(exp.get("timestamp"))
|
||||
td.append(
|
||||
[exp["rev"][:7], exp.get("name", ""), created, exp["status"]]
|
||||
)
|
||||
td.render()
|
||||
|
||||
if not result:
|
||||
ui.write("No experiments in task queue for now.")
|
||||
if result:
|
||||
all_headers = ["Task", "Name", "Created", "Status"]
|
||||
td = TabularData(all_headers)
|
||||
for exp in result:
|
||||
created = format_time(exp.get("timestamp"))
|
||||
td.append(
|
||||
[
|
||||
exp["rev"][:7],
|
||||
exp.get("name", ""),
|
||||
created,
|
||||
exp["status"],
|
||||
]
|
||||
)
|
||||
td.render()
|
||||
else:
|
||||
ui.write("No experiment tasks in the queue.")
|
||||
ui.write()
|
||||
|
||||
worker_status = self.repo.experiments.celery_queue.worker_status()
|
||||
active_count = len(
|
||||
@@ -37,25 +43,15 @@ class CmdQueueStatus(CmdBase):
|
||||
)
|
||||
idle_count = len(worker_status) - active_count
|
||||
|
||||
if active_count == 1:
|
||||
ui.write("There is 1 worker active", end=", ")
|
||||
elif active_count == 0:
|
||||
ui.write("No worker active", end=", ")
|
||||
else:
|
||||
ui.write(f"There are {active_count} workers active", end=", ")
|
||||
|
||||
if idle_count == 1:
|
||||
ui.write("1 worker idle at present.")
|
||||
elif idle_count == 0:
|
||||
ui.write("no worker idle at present.")
|
||||
else:
|
||||
ui.write(f"{idle_count} workers idle at present.")
|
||||
ui.write(f"Worker status: {active_count} active, {idle_count} idle")
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def add_parser(queue_subparsers, parent_parser):
|
||||
QUEUE_STATUS_HELP = "List the status of the queue tasks and workers."
|
||||
QUEUE_STATUS_HELP = (
|
||||
"Show the status of experiments queue tasks and workers."
|
||||
)
|
||||
queue_status_parser = queue_subparsers.add_parser(
|
||||
"status",
|
||||
parents=[parent_parser],
|
||||
|
||||
@@ -98,7 +98,7 @@ def test_experiments_stop(dvc, scm, mocker):
|
||||
[
|
||||
(
|
||||
{"worker1": [], "worker2": []},
|
||||
"No worker active, 2 workers idle at present.",
|
||||
"Worker status: 0 active, 2 idle",
|
||||
),
|
||||
(
|
||||
{
|
||||
@@ -106,11 +106,11 @@ def test_experiments_stop(dvc, scm, mocker):
|
||||
"worker2": [{"id": "2"}],
|
||||
"worker3": [],
|
||||
},
|
||||
"There are 2 workers active, 1 worker idle at present.",
|
||||
"Worker status: 2 active, 1 idle",
|
||||
),
|
||||
(
|
||||
{"worker1": [{"id": "1"}]},
|
||||
"There is 1 worker active, no worker idle at present.",
|
||||
"Worker status: 1 active, 0 idle",
|
||||
),
|
||||
],
|
||||
)
|
||||
@@ -137,7 +137,7 @@ def test_worker_status(dvc, scm, worker_status, output, mocker, capsys):
|
||||
assert cmd.run() == 0
|
||||
m.assert_called_once_with()
|
||||
log, _ = capsys.readouterr()
|
||||
assert "No experiments in task queue for now." in log
|
||||
assert "No experiment tasks in the queue." in log
|
||||
assert output in log
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user