def messenger():
while True:
sleep(5)
app.logger.debug("Inside Messenger Iteration")
msgs = poll_topics()
ads = dict()
for topic in msgs.keys():
all_msgs = msgs[topic]
ads[topic] = dict()
for msg in all_msgs:
offset = msg[2]
ad = msg[-1]
ads[topic][offset] = ad
# offset = msg.offset
# ad = msg.value
# try:
# ads[topic][offset] = ad
# except KeyError:
# ads[topic] = dict
# ads[topic][offset] = ad
for sid in client_dict.keys():
interest_list = client_dict[sid].keys()
for interest in interest_list:
regions = client_dict[sid][interest].keys()
for region in regions:
if client_dict[sid][interest][region][0]:
offset = client_dict[sid][interest][region][1]
while True:
try:
topic = interest+'_'+region
app.logger.debug('Emitting to server with topic ' + topic)
ad = ads[topic][offset]
# if len(ad) == 0:
# app.logger.debug('ad length was 0')
# continue
socketio.emit('server-message', {'topic': topic, 'ad': ad}, room=sid, callback=ack)
offset += 1
except KeyError:
app.logger.debug("Key Error Exception happened")
break
评论列表
文章目录