mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-15 22:13:00 +00:00
restart the proxy if it goes down
and populate its table from the database
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
# Copyright (c) Jupyter Development Team.
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
|
||||
import errno
|
||||
import json
|
||||
import uuid
|
||||
|
||||
@@ -94,6 +95,19 @@ class Server(Base):
|
||||
def wait_up(self, timeout=10):
|
||||
"""Wait for this server to come up"""
|
||||
yield wait_for_server(self.ip or 'localhost', self.port, timeout=timeout)
|
||||
|
||||
def is_up(self):
|
||||
"""Is the server accepting connections?"""
|
||||
try:
|
||||
socket.create_connection((self.ip or 'localhost', self.port))
|
||||
except socket.error as e:
|
||||
if e.errno == errno.ECONNREFUSED:
|
||||
return True
|
||||
else:
|
||||
raise
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
|
||||
class Proxy(Base):
|
||||
@@ -146,6 +160,21 @@ class Proxy(Base):
|
||||
)
|
||||
r.raise_for_status()
|
||||
|
||||
@gen.coroutine
|
||||
def add_all_users(self):
|
||||
"""Update the proxy table from the database.
|
||||
|
||||
Used when loading up a new proxy.
|
||||
"""
|
||||
db = inspect(self).session
|
||||
futures = []
|
||||
for user in db.query(User):
|
||||
if (user.server):
|
||||
futures.append(self.add_user(user))
|
||||
# wait after submitting them all
|
||||
for f in futures:
|
||||
yield f
|
||||
|
||||
|
||||
class Hub(Base):
|
||||
"""Bring it all together at the hub.
|
||||
|
Reference in New Issue
Block a user