Skip to content

Commit

Permalink
Replace current_ip and current_port by ip and port
Browse files Browse the repository at this point in the history
  • Loading branch information
cmd-ntrf committed Mar 28, 2019
1 parent 383e8a3 commit 648cf4c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
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

0 comments on commit 648cf4c

Please sign in to comment.