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

Replace current_ip and current_port by ip and port #139

Merged
merged 1 commit into from
Jun 18, 2019
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
9 changes: 5 additions & 4 deletions batchspawner/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
class BatchSpawnerAPIHandler(APIHandler):
@web.authenticated
def post(self):
"""POST set user's spawner port number"""
"""POST set user spawner data"""
user = self.get_current_user()
data = self.get_json_body()
port = int(data.get('port', 0))
user.spawner.current_port = port
self.finish(json.dumps({"message": "BatchSpawner port configured"}))
for key, value in data.items():
if hasattr(user.spawner, key):
setattr(user.spawner, key, value)
self.finish(json.dumps({"message": "BatchSpawner data configured"}))
self.set_status(201)

default_handlers.append((r"/api/batchspawner", BatchSpawnerAPIHandler))
23 changes: 10 additions & 13 deletions batchspawner/batchspawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,6 @@ def _req_keepvars_default(self):
# Will get the raw output of the job status command unless overridden
job_status = Unicode()

# Will get the address of the server as reported by job manager
current_ip = Unicode()

# Will get the port of the server as reported by singleserver
current_port = Integer()

# Prepare substitution variables for templates using req_xyz traits
def get_req_subvars(self):
reqlist = [ t for t in self.trait_names() if t.startswith('req_') ]
Expand Down Expand Up @@ -349,6 +343,9 @@ def poll(self):
@gen.coroutine
def start(self):
"""Start the process"""
self.ip = self.traits()['ip'].default_value
self.port = self.traits()['port'].default_value

if jupyterhub.version_info >= (0,8) and self.server:
self.server.port = self.port

Expand All @@ -375,20 +372,20 @@ def start(self):
' after starting.')
yield gen.sleep(self.startup_poll_interval)

self.current_ip = self.state_gethost()
while self.current_port == 0:
self.ip = self.state_gethost()
while self.port == 0:
yield gen.sleep(self.startup_poll_interval)

if jupyterhub.version_info < (0,7):
# store on user for pre-jupyterhub-0.7:
self.user.server.port = self.current_port
self.user.server.ip = self.current_ip
self.user.server.port = self.port
self.user.server.ip = self.ip
self.db.commit()
self.log.info("Notebook server job {0} started at {1}:{2}".format(
self.job_id, self.current_ip, self.current_port)
self.job_id, self.ip, self.port)
)

return self.current_ip, self.current_port
return self.ip, self.port

@gen.coroutine
def stop(self, now=False):
Expand All @@ -408,7 +405,7 @@ def stop(self, now=False):
yield gen.sleep(1.0)
if self.job_id:
self.log.warn("Notebook server job {0} at {1}:{2} possibly failed to terminate".format(
self.job_id, self.current_ip, self.port)
self.job_id, self.ip, self.port)
)


Expand Down