Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add close worker button to worker info page #8742

Merged
merged 4 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions distributed/http/scheduler/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from tornado import escape
from tornado.websocket import WebSocketHandler

import dask
from dask.typing import Key
from dask.utils import format_bytes, format_time

Expand All @@ -32,6 +33,10 @@

logger = logging.getLogger(__name__)

API_ENABLED = "distributed.http.scheduler.api" in dask.config.get(
"distributed.scheduler.http.routes"
)


class Workers(RequestHandler):
@log_errors
Expand All @@ -40,6 +45,7 @@ def get(self):
"workers.html",
title="Workers",
scheduler=self.server,
api_enabled=API_ENABLED,
**merge(
self.server.__dict__,
self.server.__pdict__,
Expand All @@ -62,6 +68,7 @@ def get(self, worker):
"worker.html",
title="Worker: " + worker,
scheduler=self.server,
api_enabled=API_ENABLED,
Worker=worker,
**merge(
self.server.__dict__,
Expand Down Expand Up @@ -134,6 +141,7 @@ def get(self, task: str) -> None:
title=f"Task: {key!r}",
Task=key,
scheduler=self.server,
api_enabled=API_ENABLED,
**merge(
self.server.__dict__,
self.server.__pdict__,
Expand Down
37 changes: 37 additions & 0 deletions distributed/http/templates/worker-table.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
<th> Services</th>
<th> Logs </th>
<th> Last seen </th>
{% if api_enabled %}
<th> </th>
{% else %}
{% end %}
</tr>
</thead>
<tbody>
Expand All @@ -33,7 +37,40 @@
{% end %}
<td> <a href="../logs/{{ url_escape(ws.address) }}.html">logs</a></td>
<td> {{ format_time(time() - ws.last_seen) }} </td>
{% if api_enabled %}
<td>
<form action="" id="close-worker" method="post" name="asdf">
<button class="button is-default" name="{{ws.address}}">Close</button>
</form>
</td>
{% else %}
{% end %}
</tr>
{% end %}
</tbody>
</table>

<script>
const forms = document.querySelectorAll("#close-worker");
forms.forEach(p =>
p.addEventListener("submit", (event) => {
let submitter = event.submitter;
let handler = submitter.id;
event.preventDefault();
closeWorker(submitter.name);
})
);

async function closeWorker(address) {
try {
const response = await fetch("../../api/v1/retire_workers", {
method: "POST",
body: JSON.stringify({workers: [address]}),
});
console.log(await response.json());
} catch (e) {
console.error(e);
}
}

</script>
Loading