Mercurial > code > home > repos > homeauto
comparison service/piNode/piNode.py @ 1076:d0ca77a3faf4
rewrite oneShotPost to ease debugging. add try-block around polling
Ignore-this: b7eef1b0b66fe0ba5d2c269bd1e5e37f
darcs-hash:2756095383b97972bfc56217654d9048c6d2eb86
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Thu, 14 Apr 2016 00:16:58 -0700 |
parents | 069fa84d92eb |
children | fc0e42933baa |
comparison
equal
deleted
inserted
replaced
1075:32bbce76134e | 1076:d0ca77a3faf4 |
---|---|
80 | 80 |
81 def startPolling(self): | 81 def startPolling(self): |
82 task.LoopingCall(self._poll).start(.05) | 82 task.LoopingCall(self._poll).start(.05) |
83 | 83 |
84 def _poll(self): | 84 def _poll(self): |
85 try: | |
86 self._pollMaybeError() | |
87 except Exception: | |
88 log.exception("During poll:") | |
89 | |
90 def _pollMaybeError(self): | |
85 for i in self._devs: | 91 for i in self._devs: |
86 now = time.time() | 92 now = time.time() |
87 if (hasattr(i, 'pollPeriod') and | 93 if (hasattr(i, 'pollPeriod') and |
88 self._lastPollTime.get(i.uri, 0) + i.pollPeriod > now): | 94 self._lastPollTime.get(i.uri, 0) + i.pollPeriod > now): |
89 continue | 95 continue |
113 self._exportToGraphite() | 119 self._exportToGraphite() |
114 | 120 |
115 def _sendOneshot(self, oneshot): | 121 def _sendOneshot(self, oneshot): |
116 body = (' '.join('%s %s %s .' % (s.n3(), p.n3(), o.n3()) | 122 body = (' '.join('%s %s %s .' % (s.n3(), p.n3(), o.n3()) |
117 for s,p,o in oneshot)).encode('utf8') | 123 for s,p,o in oneshot)).encode('utf8') |
118 bang6 = 'fcb8:4119:fb46:96f8:8b07:1260:0f50:fcfa' | 124 bang = '[fcb8:4119:fb46:96f8:8b07:1260:0f50:fcfa]' |
119 fetch(method='POST', | 125 url = 'http://%s:9071/oneShot' % bang |
120 url='http://[%s]:9071/oneShot' % bang6, | 126 d = fetch(method='POST', |
121 headers={'Content-Type': ['text/n3']}, postdata=body, | 127 url=url, |
122 timeout=5) | 128 headers={'Content-Type': ['text/n3']}, |
129 postdata=body, | |
130 timeout=5) | |
131 def err(e): | |
132 log.info('oneshot post to %r failed: %s', | |
133 url, e.getErrorMessage()) | |
134 d.addErrback(err) | |
123 | 135 |
124 def _exportToGraphite(self): | 136 def _exportToGraphite(self): |
125 # note this is writing way too often- graphite is storing at a lower res | 137 # note this is writing way too often- graphite is storing at a lower res |
126 now = time.time() | 138 now = time.time() |
127 # 20 sec is not precise; just trying to reduce wifi traffic | 139 # 20 sec is not precise; just trying to reduce wifi traffic |