File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 1111from tornado import escape
1212from tornado .websocket import WebSocketHandler
1313
14+ import dask
1415from dask .typing import Key
1516from dask .utils import format_bytes , format_time
1617
3233
3334logger = logging .getLogger (__name__ )
3435
36+ API_ENABLED = "distributed.http.scheduler.api" in dask .config .get (
37+ "distributed.scheduler.http.routes"
38+ )
39+
3540
3641class 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__ ,
Original file line number Diff line number Diff line change 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 >
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 >
You can’t perform that action at this time.
0 commit comments