jupyterhub / batchspawner

Custom Spawner for Jupyterhub to start servers in batch scheduled systems
BSD 3-Clause "New" or "Revised" License
190 stars 134 forks source link

Need to import batchspawner.api in jupyterhub_config.py #126

Closed dstndstn closed 5 years ago

dstndstn commented 6 years ago

Hi,

I've just got my jupyterhub + profilespawner + batchspawner setup working on a typical academic compute cluster (slurm). Thanks for all your work on this -- it's impressively slick!

I found that I had to add an "import batchspawner.api" to my jupyterhub_config.py file, otherwise the batchspawner's API endpoint didn't get registered. Unless I have done something wrong, it would be worth adding a one-liner to the README file to this effect. (I'll send a PR if you tell me that I'm not wrong.)

Specifically, my jupyterhub_config looks like this, and without the import, the API endpoint gets called but not responded-to!

import batchspawner.api

c.JupyterHub.spawner_class = 'wrapspawner.ProfilesSpawner'
c.Spawner.http_timeout = 120

c.ProfilesSpawner.profiles = [
    ('Head node', 'head', 'sudospawner.SudoSpawner', {}),
    ('Compute node - 4 cores, 4 GB, 8 hours', 'node4c4g8h', 'batchspawner.SlurmSpawner',
              dict(req_nprocs='4', req_partition='defq', req_runtime='8:00:00', req_memory='4gb')),
]

c.SlurmSpawner.batch_submit_cmd = '/home2/jupyterhub/jupyterhub-run/slurmspawner --parsable'

Thanks!

jd-daniels commented 5 years ago

+1 on this, thanks so much, been banging my head against a wall troubleshooting this.

If you don't do this. You get a 404 from the singleserver auth call back to the hub.

cmd-ntrf commented 5 years ago

I have made some progress on this issue.

batchspawner.api adds the handler to jupyterhub.default_handlers. When we use batchspawner directly in jupyterhub_config, the import of the api file is done before the JupyterHub app is launched and the batchspawner api handler is correctly appended to the Hub list of handlers.

However, when it is configurer through wrapspawner, the import of batchspawner.api come after jupyterhub app is initialized, and it is too late to add content do jupyterhub.default_handlers.

Now that I know what is the issue, I am going to try to find a solution...

cmd-ntrf commented 5 years ago

After a few hours of research, it appears that the only way to add a custom handler to JupyterHub except for what I already did in batchspawner.api is to add the api handler in jupyterhub_config.py.

So instead of import batchspawner.api, to solve your initial issue you could add the following line to your jupyterhub_config.py:

c.JupyterHub.extra_handlers = [(r"/api/batchspawner", 'batchspawner.api.BatchSpawnerAPIHandler')]

We will need to add this line to the documentation.