Changeset - 5668ad92a98e
[Not reviewed]
default
0 1 0
Drew Perttula - 7 years ago 2018-06-08 09:14:36
drewp@bigasterisk.com
bug in collector log
Ignore-this: aa0d13a3d59c156de00d48939af36145
1 file changed with 1 insertions and 1 deletions:
0 comments (0 inline, 0 general)
bin/collector
Show inline comments
 
@@ -45,49 +45,49 @@ def startZmq(port, collector):
 
                              scales.PmfStat('setAttr'))
 
    
 
    zf = ZmqFactory()
 
    addr = 'tcp://*:%s' % port
 
    log.info('creating zmq endpoint at %r', addr)
 
    e = ZmqEndpoint('bind', addr)
 
    s = ZmqPullConnection(zf, e)
 
    def onPull(message):
 
        with stats.setAttr.time():
 
            # todo: new compressed protocol where you send all URIs up
 
            # front and then use small ints to refer to devices and
 
            # attributes in subsequent requests.
 
            client, clientSession, settings, sendTime = parseJsonMessage(message[0])
 
            collector.setAttrs(client, clientSession, settings, sendTime)
 
    s.onPull = onPull
 

	
 
class WebListeners(object):
 
    def __init__(self):
 
        self.clients = []
 
        self.pendingMessageForDev = {} # dev: (attrs, outputmap)
 
        self.lastFlush = 0
 
        
 
    def addClient(self, client):
 
        self.clients.append([client, {}]) # seen = {dev: attrs}
 
        log.info('added client %s %s', len(clients), client)
 
        log.info('added client %s %s', len(self.clients), client)
 

	
 
    def delClient(self, client):
 
        self.clients = [[c, t] for c, t in self.clients if c != client]
 
        log.info('delClient %s, %s left', client, len(self.clients))
 
        
 
    def outputAttrsSet(self, dev, attrs, outputMap):
 
        """called often- don't be slow"""
 

	
 
        self.pendingMessageForDev[dev] = (attrs, outputMap)
 
        self._flush()
 

	
 
    def _flush(self):
 
        now = time.time()
 
        if now < self.lastFlush + .05 or not self.clients:
 
            return
 
        self.lastFlush = now
 

	
 
        while self.pendingMessageForDev:
 
            dev, (attrs, outputMap) = self.pendingMessageForDev.popitem()
 

	
 
            msg = None # lazy, since makeMsg is slow
 
            
 
            # this omits repeats, but can still send many
 
            # messages/sec. Not sure if piling up messages for the browser
0 comments (0 inline, 0 general)