Mercurial > code > home > repos > rdfdb
changeset 69:6b01e1e5859b
drop patches and log, but don't otherwise error, if we're not connected to rdfdb
Ignore-this: bc95e8005e78e5d78e061cb6dc73668a
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Sat, 01 Jun 2019 20:03:44 +0000 |
parents | 108260060f2c |
children | 04bd89cd9cf0 |
files | rdfdb/service.py rdfdb/syncedgraph.py |
diffstat | 2 files changed, 10 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/rdfdb/service.py Sat Jun 01 20:03:05 2019 +0000 +++ b/rdfdb/service.py Sat Jun 01 20:03:44 2019 +0000 @@ -262,9 +262,9 @@ self.watchedFiles.dirtyFiles([ctx]) graphStats.statements = len(self.graph) - def _syncPatchToOtherClients(self, p: Patch, sender: str): + def _syncPatchToOtherClients(self, p: Patch, sender: Optional[str]=None): for c in self.clients: - if c.connectionId == sender: + if sender is not None and c.connectionId == sender: # this client has self-applied the patch already log.debug("_syncPatchToOtherClients: don't resend to %r", c) continue
--- a/rdfdb/syncedgraph.py Sat Jun 01 20:03:05 2019 +0000 +++ b/rdfdb/syncedgraph.py Sat Jun 01 20:03:44 2019 +0000 @@ -49,6 +49,7 @@ def onOpen(self): log.info('ws open') + self.sg.isConnected = True def onMessage(self, payload, isBinary): msg = json.loads(payload) @@ -77,6 +78,7 @@ def onClose(self, wasClean, code, reason): log.info("WebSocket connection closed: {0}".format(reason)) + self.sg.isConnected = False class SyncedGraph(CurrentStateGraphApi, AutoDepGraphApi, GraphEditApi): """ @@ -112,7 +114,8 @@ receiverHost is the hostname other nodes can use to talk to me """ - + self.isConnected = False + self.currentClient: Optional[WsClientProtocol] = None self.connectSocket(rdfdbRoot) self.rdfdbRoot = rdfdbRoot self.initiallySynced: defer.Deferred[None] = defer.Deferred() @@ -162,6 +165,10 @@ """send this patch to the server and apply it to our local graph and run handlers""" + if not self.isConnected or self.currentClient is None: + log.warn("not currently connected- dropping patch") + return + if p.isNoop(): log.info("skipping no-op patch") return