Skip to content

Commit 8564dc7

Browse files
authored
Add close worker button to worker info page (#8742)
1 parent a57ab42 commit 8564dc7

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

distributed/http/scheduler/info.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from tornado import escape
1212
from tornado.websocket import WebSocketHandler
1313

14+
import dask
1415
from dask.typing import Key
1516
from dask.utils import format_bytes, format_time
1617

@@ -32,6 +33,10 @@
3233

3334
logger = logging.getLogger(__name__)
3435

36+
API_ENABLED = "distributed.http.scheduler.api" in dask.config.get(
37+
"distributed.scheduler.http.routes"
38+
)
39+
3540

3641
class Workers(RequestHandler):
3742
@log_errors
@@ -40,6 +45,7 @@ def get(self):
4045
"workers.html",
4146
title="Workers",
4247
scheduler=self.server,
48+
api_enabled=API_ENABLED,
4349
**merge(
4450
self.server.__dict__,
4551
self.server.__pdict__,
@@ -62,6 +68,7 @@ def get(self, worker):
6268
"worker.html",
6369
title="Worker: " + worker,
6470
scheduler=self.server,
71+
api_enabled=API_ENABLED,
6572
Worker=worker,
6673
**merge(
6774
self.server.__dict__,
@@ -134,6 +141,7 @@ def get(self, task: str) -> None:
134141
title=f"Task: {key!r}",
135142
Task=key,
136143
scheduler=self.server,
144+
api_enabled=API_ENABLED,
137145
**merge(
138146
self.server.__dict__,
139147
self.server.__pdict__,

distributed/http/templates/worker-table.html

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
<th> Services</th>
1313
<th> Logs </th>
1414
<th> Last seen </th>
15+
{% if api_enabled %}
16+
<th> </th>
17+
{% else %}
18+
{% end %}
1519
</tr>
1620
</thead>
1721
<tbody>
@@ -33,7 +37,40 @@
3337
{% end %}
3438
<td> <a href="../logs/{{ url_escape(ws.address) }}.html">logs</a></td>
3539
<td> {{ format_time(time() - ws.last_seen) }} </td>
40+
{% if api_enabled %}
41+
<td>
42+
<form action="" id="close-worker" method="post" name="asdf">
43+
<button class="button is-default" name="{{ws.address}}">Close</button>
44+
</form>
45+
</td>
46+
{% else %}
47+
{% end %}
3648
</tr>
3749
{% end %}
3850
</tbody>
3951
</table>
52+
53+
<script>
54+
const forms = document.querySelectorAll("#close-worker");
55+
forms.forEach(p =>
56+
p.addEventListener("submit", (event) => {
57+
let submitter = event.submitter;
58+
let handler = submitter.id;
59+
event.preventDefault();
60+
closeWorker(submitter.name);
61+
})
62+
);
63+
64+
async function closeWorker(address) {
65+
try {
66+
const response = await fetch("../../api/v1/retire_workers", {
67+
method: "POST",
68+
body: JSON.stringify({workers: [address]}),
69+
});
70+
console.log(await response.json());
71+
} catch (e) {
72+
console.error(e);
73+
}
74+
}
75+
76+
</script>

0 commit comments

Comments
 (0)