From 0dc315076255d383ab26d8b02cc4c93ec49389bc Mon Sep 17 00:00:00 2001 From: Min RK Date: Fri, 6 Feb 2015 14:25:27 -0800 Subject: [PATCH] add Proxy.check_routes checks to ensure proxy table and user db are in sync called on each last-activity check with the proxy (5 minutes) --- jupyterhub/app.py | 1 + jupyterhub/orm.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/jupyterhub/app.py b/jupyterhub/app.py index 3d594aa5..df42bf38 100644 --- a/jupyterhub/app.py +++ b/jupyterhub/app.py @@ -869,6 +869,7 @@ class JupyterHub(Application): user.last_activity = max(user.last_activity, dt) self.db.commit() + yield self.proxy.check_routes(routes) @gen.coroutine def start(self): diff --git a/jupyterhub/orm.py b/jupyterhub/orm.py index d1cefdeb..9ee86344 100644 --- a/jupyterhub/orm.py +++ b/jupyterhub/orm.py @@ -193,6 +193,23 @@ class Proxy(Base): resp = yield self.api_request('', client=client) return json.loads(resp.body.decode('utf8', 'replace')) + @gen.coroutine + def check_routes(self, routes=None): + """Check that all users are properly""" + if not routes: + routes = yield self.get_routes() + + have_routes = { r['user'] for r in routes if 'user' in r } + futures = [] + db = inspect(self).session + for user in db.query(User).filter(User.server != None): + if user.name not in have_routes: + self.log.warn("Adding missing route for %s", user.name) + futures.append(self.add_user(user)) + for f in futures: + yield f + + class Hub(Base): """Bring it all together at the hub.