Skip to content

Commit c45f253

Browse files
committed
bin: allow operator to release all held workers
1 parent b8ac7ac commit c45f253

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

bin/src/main.rs

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,18 +1549,51 @@ async fn do_worker_hold(mut l: Level<Stuff>) -> Result<()> {
15491549
}
15501550

15511551
async fn do_worker_release(mut l: Level<Stuff>) -> Result<()> {
1552-
l.usage_args(Some("WORKER..."));
1552+
l.usage_args(Some("all|WORKER..."));
1553+
1554+
l.optflag("v", "verbose", "print details about profile");
15531555

15541556
let a = args!(l);
1555-
if a.args().is_empty() {
1557+
let c = l.context();
1558+
1559+
let verbose = a.opts().opt_present("v");
1560+
let to_release = if a.args().is_empty() {
15561561
bad_args!(l, "specify a worker to release");
1557-
}
1562+
} else if a.args().iter().any(|w| w == "all") {
1563+
if a.args().len() != 1 {
1564+
bad_args!(l, "\"all\" must be the only argument");
1565+
}
15581566

1559-
for arg in a.args() {
1560-
if let Err(e) =
1561-
l.context().admin().worker_hold_release().worker(arg).send().await
1567+
/*
1568+
* Get a list of held workers to release.
1569+
*/
1570+
let mut workers = c.admin().workers_list().active(true).stream();
1571+
let mut to_release = Vec::new();
1572+
while let Some(w) = workers.try_next().await? {
1573+
if w.deleted || w.hold.is_none() {
1574+
continue;
1575+
}
1576+
1577+
to_release.push(w.id);
1578+
}
1579+
1580+
if verbose {
1581+
println!("found {} held workers to release", to_release.len());
1582+
}
1583+
1584+
to_release
1585+
} else {
1586+
a.args().to_vec()
1587+
};
1588+
1589+
for id in &to_release {
1590+
if verbose {
1591+
println!("releasing worker {id}");
1592+
}
1593+
1594+
if let Err(e) = c.admin().worker_hold_release().worker(id).send().await
15621595
{
1563-
bail!("ERROR: releasing hold on {arg}: {e:?}");
1596+
bail!("ERROR: releasing hold on {id}: {e:?}");
15641597
}
15651598
}
15661599

0 commit comments

Comments
 (0)