changeset 135:605ea6ce409e

py-client write requests weren't working at all
author drewp@bigasterisk.com
date Wed, 31 May 2023 00:43:42 -0700
parents d3d6a1f62222
children 8fa6a47521d7
files rdfdb/syncedgraph/grapheditapi.py rdfdb/syncedgraph/syncedgraph_base.py
diffstat 2 files changed, 9 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/rdfdb/syncedgraph/grapheditapi.py	Mon May 29 23:20:55 2023 -0700
+++ b/rdfdb/syncedgraph/grapheditapi.py	Wed May 31 00:43:42 2023 -0700
@@ -1,3 +1,4 @@
+import asyncio
 import logging
 import random
 from itertools import chain
@@ -35,7 +36,7 @@
         p = self.getObjectPatch(context, subject, predicate, newObject)
         if not p.isEmpty():
             log.debug("patchObject %r" % p.jsonRepr)
-        self.patch(p)  # type: ignore
+        asyncio.create_task(self.patch(p))
 
     def patchSubgraph(self, context, newGraph):
         """
@@ -45,7 +46,7 @@
         old = set(quadsWithContextUris(self._graph.quads((None, None, None, context))))
         new = set(quadsWithContextUris(newGraph))
         p = Patch(delQuads=old - new, addQuads=new - old)
-        self.patch(p)
+        asyncio.create_task(self.patch(p))
         return p  # for debugging
 
     def patchMapping(self, context, subject, predicate, nodeClass, keyPred, valuePred, newKey, newValue):
@@ -88,7 +89,7 @@
             adds.add((setting, valuePred, newValue, context))
 
             if adds != dels:
-                self.patch(Patch(delQuads=dels, addQuads=adds))
+                asyncio.create_task(self.patch(Patch(delQuads=dels, addQuads=adds)))
 
     def removeMappingNode(self, context, node):
         """
@@ -100,4 +101,4 @@
             spo + (context,)
             for spo in chain(self._graph.triples((None, None, node), context=context), self._graph.triples((node, None, None), context=context))
         ])
-        self.patch(p)
+        asyncio.create_task(self.patch(p))
--- a/rdfdb/syncedgraph/syncedgraph_base.py	Mon May 29 23:20:55 2023 -0700
+++ b/rdfdb/syncedgraph/syncedgraph_base.py	Wed May 31 00:43:42 2023 -0700
@@ -133,6 +133,9 @@
             log.warning("_CorruptionNeedResync")
         await self._lostRdfdbConnection()
 
+    def _isConnected(self):
+        return getattr(self, 'ws', False) and not self.ws.closed # todo- can we just not have this?
+
     async def _onIncomingMsg(self, body: str):
         j = json.loads(body)
         if 'connectedAs' in j:
@@ -146,8 +149,6 @@
             log.warn('unknown msg from websocket: %s...', body[:32])
 
     async def _lostRdfdbConnection(self) -> None:
-        self.isConnected = False
-
         # correct but ineffecient-- better to wait until new connection and apply only the diff
         log.debug(f'graph has {len(self._graph)} . lets clear it')
         await self._patchLocally(Patch(delQuads=self._graph.quads()))
@@ -164,7 +165,7 @@
         """send this patch to the server and apply it to our local
         graph and run handlers"""
 
-        if not self.isConnected:
+        if not self._isConnected():
             # todo: queue these. it's not the caller's problem
             log.warn("not currently connected- dropping patch")
             return