Mercurial > code > home > repos > homeauto
comparison service/collector/sse_collector.py @ 595:7fd9fa5d33aa
standardize build. fix /state report
Ignore-this: 5a9bc82de9f0d7398c9290fc2c7ecbf9
author | drewp@bigasterisk.com |
---|---|
date | Sat, 06 Jul 2019 13:56:07 -0700 |
parents | 91ab9f926aa1 |
children | 22751570eda1 |
comparison
equal
deleted
inserted
replaced
594:137fa1ba5321 | 595:7fd9fa5d33aa |
---|---|
23 from twisted.internet import reactor, defer | 23 from twisted.internet import reactor, defer |
24 from typing import Callable, Dict, NewType, Tuple, Union, Any, Sequence, Set, List, Optional | 24 from typing import Callable, Dict, NewType, Tuple, Union, Any, Sequence, Set, List, Optional |
25 import cyclone.web, cyclone.sse | 25 import cyclone.web, cyclone.sse |
26 import logging, collections, json, time | 26 import logging, collections, json, time |
27 | 27 |
28 from logsetup import log, enableTwistedLog | 28 from standardservice.logsetup import log, enableTwistedLog |
29 from patchablegraph import jsonFromPatch | 29 from patchablegraph import jsonFromPatch |
30 from rdfdb.patch import Patch | 30 from rdfdb.patch import Patch |
31 | 31 |
32 # workaround for broken import in twisted_sse_demo/eventsourcee.py | 32 from patchablegraph.patchsource import ReconnectingPatchSource |
33 import sys; sys.path.append('twisted_sse_demo') | |
34 from patchsource import ReconnectingPatchSource | |
35 | 33 |
36 from sse_collector_config import config | 34 from sse_collector_config import config |
37 | 35 |
38 #SourceUri = NewType('SourceUri', URIRef) # doesn't work | 36 #SourceUri = NewType('SourceUri', URIRef) # doesn't work |
39 class SourceUri(URIRef): pass | 37 class SourceUri(URIRef): pass |
415 class State(cyclone.web.RequestHandler): | 413 class State(cyclone.web.RequestHandler): |
416 @STATS.getState.time() | 414 @STATS.getState.time() |
417 def get(self) -> None: | 415 def get(self) -> None: |
418 try: | 416 try: |
419 state = self.settings.graphClients.state() | 417 state = self.settings.graphClients.state() |
420 except: | 418 self.write(json.dumps({'graphClients': state}, indent=2, |
419 default=lambda obj: '<unserializable>')) | |
420 except Exception: | |
421 import traceback; traceback.print_exc() | 421 import traceback; traceback.print_exc() |
422 raise | 422 raise |
423 | 423 |
424 self.write(json.dumps({'graphClients': state}, indent=2)) | |
425 | |
426 | 424 |
427 class Root(cyclone.web.RequestHandler): | 425 class Root(cyclone.web.RequestHandler): |
428 def get(self) -> None: | 426 def get(self) -> None: |
429 self.write('<html><body>sse_collector</body></html>') | 427 self.write('<html><body>sse_collector</body></html>') |
430 | 428 |