Mercurial > code > home > repos > homeauto
changeset 271:e7a30f72536a
rewrite oneShotPost to ease debugging. add try-block around polling
Ignore-this: b7eef1b0b66fe0ba5d2c269bd1e5e37f
author | drewp@bigasterisk.com |
---|---|
date | Thu, 14 Apr 2016 00:16:58 -0700 |
parents | 9fceaaef753e |
children | 660d21bcfcde |
files | service/piNode/piNode.py |
diffstat | 1 files changed, 17 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/service/piNode/piNode.py Thu Apr 14 00:16:27 2016 -0700 +++ b/service/piNode/piNode.py Thu Apr 14 00:16:58 2016 -0700 @@ -82,6 +82,12 @@ task.LoopingCall(self._poll).start(.05) def _poll(self): + try: + self._pollMaybeError() + except Exception: + log.exception("During poll:") + + def _pollMaybeError(self): for i in self._devs: now = time.time() if (hasattr(i, 'pollPeriod') and @@ -115,11 +121,17 @@ def _sendOneshot(self, oneshot): body = (' '.join('%s %s %s .' % (s.n3(), p.n3(), o.n3()) for s,p,o in oneshot)).encode('utf8') - bang6 = 'fcb8:4119:fb46:96f8:8b07:1260:0f50:fcfa' - fetch(method='POST', - url='http://[%s]:9071/oneShot' % bang6, - headers={'Content-Type': ['text/n3']}, postdata=body, - timeout=5) + bang = '[fcb8:4119:fb46:96f8:8b07:1260:0f50:fcfa]' + url = 'http://%s:9071/oneShot' % bang + d = fetch(method='POST', + url=url, + headers={'Content-Type': ['text/n3']}, + postdata=body, + timeout=5) + def err(e): + log.info('oneshot post to %r failed: %s', + url, e.getErrorMessage()) + d.addErrback(err) def _exportToGraphite(self): # note this is writing way too often- graphite is storing at a lower res