restart the proxy if it goes down

and populate its table from the database
This commit is contained in:
MinRK
2014-09-18 17:04:17 -07:00
parent 6106fecd48
commit 58b32f634a
2 changed files with 74 additions and 3 deletions

View File

@@ -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.