diff --git a/firecrestspawner/api.py b/firecrestspawner/api.py index f3441db..61f6a37 100644 --- a/firecrestspawner/api.py +++ b/firecrestspawner/api.py @@ -26,7 +26,7 @@ def post(self): if hasattr(spawner, key): setattr(spawner, key, value) - self.finish(json.dumps({"message": "BatchSpawner data configured"})) + self.finish(json.dumps({"message": "FirecRESTSpawner data configured"})) self.set_status(201) diff --git a/firecrestspawner/singleuser.py b/firecrestspawner/singleuser.py index 37f1dcb..298d60e 100644 --- a/firecrestspawner/singleuser.py +++ b/firecrestspawner/singleuser.py @@ -1,28 +1,27 @@ import os import sys -import requests - from runpy import run_path from shutil import which +from urllib.parse import urlparse -from jupyterhub.utils import random_port, url_path_join +import requests from jupyterhub.services.auth import HubAuth +from jupyterhub.utils import url_path_join def main(argv=None): - port = random_port() + url = urlparse(os.environ["JUPYTERHUB_SERVICE_URL"]) + port = url.port hub_auth = HubAuth() - hub_auth.client_ca = os.environ.get('JUPYTERHUB_SSL_CLIENT_CA', '') - hub_auth.certfile = os.environ.get('JUPYTERHUB_SSL_CERTFILE', '') - hub_auth.keyfile = os.environ.get('JUPYTERHUB_SSL_KEYFILE', '') requests.post( - url=url_path_join(hub_auth.api_url, 'firecrestspawner'), - headers = {"Authorization": f"token {hub_auth.api_token}"}, + url=url_path_join(hub_auth.api_url, "firecrestspawner"), + headers={"Authorization": f"token {hub_auth.api_token}"}, json={"port": port}, ) cmd_path = which(sys.argv[1]) - sys.argv = sys.argv[1:] + ['--port={}'.format(port)] + sys.argv = sys.argv[1:] + ["--port={}".format(port)] run_path(cmd_path, run_name="__main__") + if __name__ == "__main__": main() diff --git a/firecrestspawner/spawner.py b/firecrestspawner/spawner.py index ebb0add..8939487 100644 --- a/firecrestspawner/spawner.py +++ b/firecrestspawner/spawner.py @@ -15,7 +15,7 @@ import firecrest as f7t from enum import Enum from jinja2 import Template -from tornado import gen +# from tornado import gen from jupyterhub.spawner import Spawner from traitlets import ( Any, Integer, Unicode, Float, default @@ -341,7 +341,7 @@ async def start(self): if self.port == 0: self.port = self.traits()['port'].default_value - if jupyterhub.version_info >= (0, 8) and self.server: + if self.server: self.server.port = self.port await self.submit_batch_script() @@ -369,20 +369,10 @@ async def start(self): raise RuntimeError('The Jupyter batch job has disappeared' ' while pending in the queue or died ' ' immediately after starting.') - await gen.sleep(self.startup_poll_interval) + await asyncio.sleep(self.startup_poll_interval) self.ip = await self.state_gethost() - while self.port == 0: - await gen.sleep(self.startup_poll_interval) - # Test framework: For testing, mock_port is set because we - # don't actually run the single-user server yet. - if hasattr(self, 'mock_port'): - self.port = self.mock_port - - if jupyterhub.version_info < (0, 7): - # store on user for pre-jupyterhub-0.7: - self.user.server.port = self.port - self.user.server.ip = self.ip + self.db.commit() self.log.info(f"Notebook server job {self.job_id} started at " f"{self.ip}:{self.port}") @@ -403,7 +393,7 @@ async def stop(self, now=False): status = await self.query_job_status() if status not in (JobStatus.RUNNING, JobStatus.UNKNOWN): return - await gen.sleep(1.0) + await asyncio.sleep(1.0) if self.job_id: self.log.warning( f"Notebook server job {self.job_id} at {self.ip}:{self.port} " @@ -426,7 +416,7 @@ async def progress(self): await yield_({ "message": "Unknown status...", }) - await gen.sleep(1) + await asyncio.sleep(1) class FirecRESTSpawnerRegexStates(FirecRESTSpawnerBase):