async def push_log(): cursor = logs.find(cursor_type=CursorType.TAILABLE_AWAIT) while True: if not cursor.alive: # While collection is empty, tailable cursor dies immediately yield gen.sleep(1) cursor = logs.find(cursor_type=CursorType.TAILABLE_AWAIT) async for r in cursor: r[u'msgtype'] = 'log' msg = json.dumps(r, default=date_encoder.default) for client in client_list: client.write_message(msg)
def push_log(): cursor = logs.find(tailable=True, await_data=True) while True: if not cursor.alive: # While collection is empty, tailable cursor dies immediately yield gen.sleep(1) cursor = logs.find(tailable=True, await_data=True) if (yield cursor.fetch_next): r = cursor.next_object() r[u'msgtype'] = 'log' msg = json.dumps(r, default=date_encoder.default) for client in client_list: client.write_message(msg)
def push_log(): cursor = logs.find(tailable=True, await_data=True) while True: if not cursor.alive: # While collection is empty, tailable cursor dies immediately yield gen.sleep(1) cursor = logs.find(tailable=True, await_data=True) if (yield cursor.fetch_next): r = cursor.next_object() r[u'msgtype'] = 'log' msg = json.dumps( r, default=date_encoder.default) for client in client_list: client.write_message(msg)
def open(self): if self not in client_list: client_list.append(self) cursor = logs.find().sort('$natural', ASCENDING).limit(20) while(yield cursor.fetch_next): r = cursor.next_object() r[u'msgtype'] = 'log' self.write_message(json.dumps( r, default=date_encoder.default)) cursor = stats.find() while (yield cursor.fetch_next): r = cursor.next_object() r[u'msgtype'] = 'stats' self.write_message(json.dumps( r, default=date_encoder.default))
async def open(self): if self not in client_list: client_list.append(self) cursor = logs.find().sort('$natural', DESCENDING).limit(30) start_logs = [] async for r in cursor: r[u'msgtype'] = 'log' start_logs.append(json.dumps(r, default=date_encoder.default)) while len(start_logs): msg = start_logs.pop() self.write_message(msg) cursor = stats.find() async for r in cursor: r[u'msgtype'] = 'stats' self.write_message(json.dumps(r, default=date_encoder.default))
def open(self): if self not in client_list: client_list.append(self) cursor = logs.find().sort('$natural', DESCENDING).limit(30) start_logs = [] while (yield cursor.fetch_next): r = cursor.next_object() r[u'msgtype'] = 'log' start_logs.append(json.dumps(r, default=date_encoder.default)) while len(start_logs): msg = start_logs.pop() self.write_message(msg) cursor = stats.find() while (yield cursor.fetch_next): r = cursor.next_object() r[u'msgtype'] = 'stats' self.write_message(json.dumps(r, default=date_encoder.default))
def nope_open_async(self): if self not in client_list: client_list.append(self) logs.find().limit( 10).to_list(length=10, callback=self._got_messages)