Mercurial > code > home > repos > rdfdb
diff rdfdb/service.py @ 46:3b36b2c8ae65
fix bug that echoed a patch back to KC. https://bigasterisk.com/light9/work/2019/kc-patch-echo-bug.png
Ignore-this: 91a52a9fe4b7372a439ab0713dfe2bdc
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Mon, 27 May 2019 08:08:23 +0000 |
parents | dc61012eeace |
children | 7c3cd440619b |
line wrap: on
line diff
--- a/rdfdb/service.py Mon May 27 07:45:24 2019 +0000 +++ b/rdfdb/service.py Mon May 27 08:08:23 2019 +0000 @@ -1,24 +1,22 @@ -from twisted.internet import reactor, defer -import twisted.internet.error -from twisted.python.filepath import FilePath -from twisted.python.failure import Failure -from twisted.internet.inotify import IN_CREATE import sys, optparse, logging, json, os -import cyclone.web, cyclone.httpclient, cyclone.websocket from typing import Dict, List, Set, Optional, Union +from twisted.internet import reactor, defer +from twisted.internet.inotify import IN_CREATE, INotify +from twisted.python.failure import Failure +from twisted.python.filepath import FilePath +import cyclone.web, cyclone.httpclient, cyclone.websocket from rdflib import ConjunctiveGraph, URIRef, Graph +import twisted.internet.error + +from rdfdb.file_vs_uri import correctToTopdirPrefix, fileForUri, uriFromFile, DirUriMap from rdfdb.graphfile import GraphFile, PatchCb, GetSubgraph from rdfdb.patch import Patch, ALLSTMTS -from rdfdb.rdflibpatch import patchQuads -from rdfdb.file_vs_uri import correctToTopdirPrefix, fileForUri, uriFromFile, DirUriMap +from rdfdb.patchreceiver import makePatchEndpointPutMethod from rdfdb.patchsender import sendPatch -from rdfdb.patchreceiver import makePatchEndpointPutMethod - -from twisted.internet.inotify import INotify +from rdfdb.rdflibpatch import patchQuads log = logging.getLogger('rdfdb') -log.setLevel(logging.DEBUG) class WebsocketDisconnect(ValueError): @@ -234,17 +232,19 @@ self.watchedFiles.dirtyFiles([ctx]) sendToLiveClients(asJson=patch.jsonRepr) - def _sendPatch(self, p): - senderUpdateUri = getattr(p, 'senderUpdateUri', None) + def _sendPatch(self, p: Patch): + senderUpdateUri: Optional[URIRef] = getattr(p, 'senderUpdateUri', None) for c in self.clients: if c.updateUri == senderUpdateUri: # this client has self-applied the patch already + log.debug("_sendPatch: don't resend to %r", c) continue + log.debug('_sendPatch: send to %r', c) d = c.sendPatch(p) d.addErrback(self.clientErrored, c) - def clientErrored(self, err, c): + def clientErrored(self, err, c) -> None: err.trap(twisted.internet.error.ConnectError, WebsocketDisconnect) log.info("%r %r - dropping client", c, err.getErrorMessage()) if c in self.clients: