update proxy with already-running users at startup

This commit is contained in:
MinRK
2014-09-21 18:00:32 -07:00
parent 01323833bb
commit 2a46893448
2 changed files with 8 additions and 1 deletions

View File

@@ -447,7 +447,7 @@ class JupyterHubApp(Application):
)
self.db.add(self.proxy)
self.db.commit()
self.proxy.log = self.log
self.proxy.public_server.ip = self.ip
self.proxy.public_server.port = self.port
self.proxy.api_server.ip = self.proxy_api_ip
@@ -644,6 +644,7 @@ class JupyterHubApp(Application):
return
loop = IOLoop.current()
loop.add_callback(self.proxy.add_all_users)
if self.proxy_process:
# only check / restart the proxy if we started it in the first place.

View File

@@ -9,6 +9,7 @@ import socket
import uuid
from tornado import gen
from tornado.log import app_log
from tornado.httpclient import HTTPRequest, AsyncHTTPClient, HTTPError
from sqlalchemy.types import TypeDecorator, VARCHAR
@@ -123,6 +124,7 @@ class Proxy(Base):
public_server = relationship(Server, primaryjoin=_public_server_id == Server.id)
_api_server_id = Column(Integer, ForeignKey('servers.id'))
api_server = relationship(Server, primaryjoin=_api_server_id == Server.id)
log = app_log
def __repr__(self):
if self.public_server:
@@ -135,6 +137,9 @@ class Proxy(Base):
@gen.coroutine
def add_user(self, user, client=None):
"""Add a user's server to the proxy table."""
self.log.info("Adding user %s to proxy %s => %s",
user.name, user.server.base_url, user.server.host,
)
client = client or AsyncHTTPClient()
req = HTTPRequest(url_path_join(
@@ -154,6 +159,7 @@ class Proxy(Base):
@gen.coroutine
def delete_user(self, user, client=None):
"""Remove a user's server to the proxy table."""
self.log.info("Removing user %s from proxy", user.name)
client = client or AsyncHTTPClient()
req = HTTPRequest(url_path_join(
self.api_server.url,