dashboard: report lost connection with master. Closes #602

This commit is contained in:
Sebastien Bourdeauducq 2017-01-30 10:48:27 +08:00
parent dcea48a52d
commit 3aced46b19
2 changed files with 15 additions and 4 deletions

View File

@ -108,12 +108,21 @@ def main():
atexit.register(client.close_rpc)
rpc_clients[target] = client
disconnect_reported = False
def report_disconnect():
nonlocal disconnect_reported
if not disconnect_reported:
logging.error("connection to master lost, "
"restart dashboard to reconnect")
disconnect_reported = True
sub_clients = dict()
for notifier_name, modelf in (("explist", explorer.Model),
("explist_status", explorer.StatusUpdater),
("datasets", datasets.Model),
("schedule", schedule.Model)):
subscriber = ModelSubscriber(notifier_name, modelf)
subscriber = ModelSubscriber(notifier_name, modelf,
report_disconnect)
loop.run_until_complete(subscriber.connect(
args.server, args.port_notify))
atexit_register_coroutine(subscriber.close)
@ -121,7 +130,7 @@ def main():
broadcast_clients = dict()
for target in "log", "ccb":
client = Receiver(target, [])
client = Receiver(target, [], report_disconnect)
loop.run_until_complete(client.connect(
args.server, args.port_broadcast))
atexit_register_coroutine(client.close)

View File

@ -22,9 +22,11 @@ class ModelManager:
class ModelSubscriber(ModelManager, Subscriber):
def __init__(self, notifier_name, model_factory):
def __init__(self, notifier_name, model_factory,
disconnect_cb=None):
ModelManager.__init__(self, model_factory)
Subscriber.__init__(self, notifier_name, self._create_model)
Subscriber.__init__(self, notifier_name, self._create_model,
disconnect_cb=disconnect_cb)
class LocalModelManager(ModelManager):