Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5d8c2b0

Browse files
committed
Allow using hq worker stop last
1 parent 942e503 commit 5d8c2b0

4 files changed

Lines changed: 19 additions & 7 deletions

File tree

crates/hyperqueue/src/server/client.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,12 @@ async fn handle_worker_stop(
358358
.filter(|(_, worker)| worker.make_info().ended.is_none())
359359
.map(|(_, worker)| worker.worker_id())
360360
.collect(),
361-
_ => return ToClientMessage::Error("Invalid command was provided".parse().unwrap()),
361+
Selector::LastN(n) => {
362+
let mut ids: Vec<_> = state_ref.get().get_workers().keys().copied().collect();
363+
ids.sort_by_key(|&k| std::cmp::Reverse(k));
364+
ids.truncate(n as usize);
365+
ids
366+
}
362367
};
363368

364369
for worker_id in worker_ids {

docs/deployment/worker.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,7 @@ the option `--manager <pbs/slurm>` to tell the worker that it should expect a sp
7676
If you have started a worker manually, and you want to stop it, you can use the `hq worker stop` command[^2]:
7777

7878
```bash
79-
# Stop a specific worker
80-
$ hq worker stop <worker-id>
81-
82-
# Stop all workers
83-
$ hq worker stop all
79+
$ hq worker stop <selector>
8480
```
8581

8682
[^2]: You can use various [shortcuts](../tips/cli-shortcuts.md#id-selector) to select multiple workers at once.

docs/tips/cli-shortcuts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ select multiple IDs at once or to reference the most recently created ID:
1616
- `hq worker stop all` - stop all workers
1717
- `hq cancel all` - cancel all jobs
1818
- `last` The most recently created ID
19+
- `hq worker stop last` - stop most recently connected worker
1920
- `hq cancel last` - cancel most recently submitted job
2021

2122
You can also combine the first two types of selectors with a comma. For example, the command
@@ -29,7 +30,6 @@ would stop workers with IDs `1`, `3`, `5`, `6`, `7` and `8`.
2930
### Supported commands and options
3031
- `hq submit --array=<selector>`
3132
- `hq worker stop <selector>`
32-
- does not support `last`
3333
- `hq job <selector>`
3434
- does not support `all` (use `hq jobs` instead)
3535
- `hq cancel <selector>`

tests/test_worker.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@ def test_worker_stop_all(hq_env: HqEnv):
8686
hq_env.check_process_exited(process)
8787

8888

89+
def test_worker_stop_last(hq_env: HqEnv):
90+
hq_env.start_server()
91+
processes = [hq_env.start_worker() for i in range(4)]
92+
93+
wait_for_worker_state(hq_env, [1, 2, 3, 4], ["RUNNING" for i in range(4)]),
94+
hq_env.command(["worker", "stop", "last"])
95+
wait_for_worker_state(hq_env, [4], ["STOPPED" for i in range(4)]),
96+
97+
hq_env.check_process_exited(processes[3])
98+
99+
89100
def test_worker_list_only_online(hq_env: HqEnv):
90101
hq_env.start_server()
91102
hq_env.start_workers(2)

0 commit comments

Comments
 (0)