Skip to content

Commit b7685a1

Browse files
authored
Merge pull request #188 from ian-r-rose/only-check-json-endpoint
Don't check the root bokeh URL
2 parents 4447b39 + 4e3879c commit b7685a1

File tree

3 files changed

+38
-17
lines changed

3 files changed

+38
-17
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/psf/black
3-
rev: stable
3+
rev: 21.5b1
44
hooks:
55
- id: black
66
language_version: python3

dask_labextension/dashboardhandler.py

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,42 +29,63 @@ async def get(self, url) -> None:
2929
try:
3030
client = httpclient.AsyncHTTPClient()
3131

32-
# Check the user-provided url, following any redirects.
32+
# First check for the individual-plots endpoint at user-provided url.
33+
# We don't check for the root URL because that can trigger a lot of
34+
# object creation in the bokeh document.
3335
url = _normalize_dashboard_link(parse.unquote(url), self.request)
36+
effective_url = None
37+
individual_plots_url = url_path_join(
38+
url,
39+
"individual-plots.json",
40+
)
3441
try:
42+
self.log.debug(
43+
f"Checking for individual plots at {individual_plots_url}"
44+
)
45+
individual_plots_response = await client.fetch(individual_plots_url)
46+
self.log.debug(f"{individual_plots_response.code}")
47+
except httpclient.HTTPError as err:
48+
# If we didn't get individual plots, we may have to follow a redirect first.
49+
self.log.debug(f"Checking for redirect at {url}")
3550
response = await client.fetch(url)
3651
effective_url = (
37-
response.effective_url if response.effective_url != url else None
52+
_normalize_dashboard_link(response.effective_url, self.request)
53+
if response.effective_url != url
54+
else None
3855
)
39-
except httpclient.HTTPError:
40-
# The page at /individual-plots.html might be available, even if `/` isn't.
41-
effective_url = None
56+
# If there was no redirect, raise.
57+
if not effective_url:
58+
raise err
59+
60+
individual_plots_url = url_path_join(
61+
effective_url,
62+
"individual-plots.json",
63+
)
64+
self.log.debug(f"Found redirect at {effective_url}")
65+
self.log.debug(
66+
f"Checking for individual plots at {individual_plots_url}"
67+
)
68+
individual_plots_response = await client.fetch(individual_plots_url)
4269

43-
# Fetch the individual plots
44-
individual_plots_url = url_path_join(
45-
_normalize_dashboard_link(effective_url or url, self.request),
46-
"individual-plots.json",
47-
)
48-
self.log.info("Checking for individual plots at %s", individual_plots_url)
49-
individual_plots_response = await client.fetch(individual_plots_url)
5070
# If we didn't get individual plots, it may not be a dask dashboard
5171
if individual_plots_response.code != 200:
5272
raise ValueError("Does not seem to host a dask dashboard")
73+
5374
individual_plots = json.loads(individual_plots_response.body)
5475

5576
self.set_status(200)
5677
self.finish(
5778
json.dumps(
5879
{
5980
"url": url,
60-
"isActive": individual_plots_response.code == 200,
81+
"isActive": True,
6182
"effectiveUrl": effective_url,
6283
"plots": individual_plots,
6384
}
6485
)
6586
)
6687
except Exception:
67-
self.log.exception(f"{url} does not seem to host a dask dashboard")
88+
self.log.debug(f"{url} does not seem to host a dask dashboard")
6889
self.set_status(200)
6990
self.finish(
7091
json.dumps(

dask_labextension/manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class DaskClusterManager:
5454
"""
5555

5656
def __init__(self) -> None:
57-
""" Initialize the cluster manager """
57+
"""Initialize the cluster manager"""
5858
self._clusters: Dict[str, Cluster] = dict()
5959
self._adaptives: Dict[str, Adaptive] = dict()
6060
self._cluster_names: Dict[str, str] = dict()
@@ -213,7 +213,7 @@ def adapt_cluster(
213213
return make_cluster_model(cluster_id, name, cluster, adaptive)
214214

215215
async def close(self):
216-
""" Close all clusters and cleanup """
216+
"""Close all clusters and cleanup"""
217217
for cluster_id in list(self._clusters):
218218
await self.close_cluster(cluster_id)
219219

0 commit comments

Comments
 (0)