async def __ensure_watched(self, action_type): while True: try: await self.__request(self.__build_watch_req(action_type)) logger.info("Watched action_type: %s", action_type) break except Exception: logger.error("Failed to watch: %s", traceback.format_exc()) await asyncio.sleep(1)
async def get_tables(): loop = asyncio.get_event_loop() client = Client("localhost:8888", loop=loop) while True: try: names, ids = await client.get_tables() logger.info("Received names: %s, ids: %s", names, ids) except Exception: logger.error("Failed to check: %s", traceback.format_exc()) await asyncio.sleep(1)
async def set_rows(): loop = asyncio.get_event_loop() client = Client("localhost:8888", loop=loop) global count while True: try: keys, values = build_rows() await client.set_rows("huobi.btc.usdt.1m", keys, values) count += 1 if count % 1000 == 0: logger.info("count: %s", count) except Exception: logger.error("Failed to check: %s", traceback.format_exc())
async def get_nth_last_value(): loop = asyncio.get_event_loop() client = Client("localhost:8888", loop=loop) global count while True: try: table = "huobi.btc.usdt.1m" value = await client.get_nth_last_value(table, 0) logger.info("Received value: %s", value) count += 1 if count % 1000 == 0: logger.info("count: %s", count) except Exception: logger.error("Failed to check: %s", traceback.format_exc()) await asyncio.sleep(1)
async def get_boundary_rows(): loop = asyncio.get_event_loop() client = Client("localhost:8888", loop=loop) global count while True: try: table = "huobi.btc.usdt.1m" rows = await client.get_boundary_rows(table) logger.info("Received rows: %s", rows) count += 1 if count % 1000 == 0: logger.info("count: %s", count) except Exception: logger.error("Failed to check: %s", traceback.format_exc()) await asyncio.sleep(1)
async def delete_rows_since(): loop = asyncio.get_event_loop() client = Client("localhost:8888", loop=loop) global count while True: try: table = "huobi.btc.usdt.1m" key = struct.pack('>I', 2) await client.delete_rows_since(table, key, 2) break count += 1 if count % 1000 == 0: logger.info("count: %s", count) except Exception: logger.error("Failed to check: %s", traceback.format_exc()) await asyncio.sleep(1)
async def get_values_until(): loop = asyncio.get_event_loop() client = Client("localhost:8888", loop=loop) global count while True: try: table = "huobi.btc.usdt.1m" key = struct.pack('>I', 3) values = await client.get_values_until(table, key, 10) logger.info("Received values: %s", values) count += 1 if count % 1000 == 0: logger.info("count: %s", count) except Exception: logger.error("Failed to check: %s", traceback.format_exc()) await asyncio.sleep(1)
async def __pull(self, topic): msg_queue = self.__msg_queue_mgr.get(topic) event = self.__events.get(topic) callback = self.__subscribe_callbacks.get(topic) offset = self.__subscription_mgr.get_doing(topic) pull_rep = await self.__request(self.__build_pull_req(topic, offset)) msg_queue.put(pull_rep.msgs) self.__subscription_mgr.to_doing(topic, msg_queue.last_offset() + 1) try: callback(topic) except Exception: logger.error("Failed to notify: %s", traceback.format_exc()) if msg_queue.is_full(): logger.info( "Msg queue is full, waiting for consuming: " "topic: %s, last offset: %s", topic, msg_queue.last_offset()) event.clear() await event.wait()
async def get_rows_between(): loop = asyncio.get_event_loop() client = Client("localhost:8888", loop=loop) global count while True: try: table = "huobi.btc.usdt.1m" begin_key = struct.pack('>I', 3) end_key = struct.pack('>I', 11) keys, values = await client.get_rows_between( table, begin_key, end_key, 3) logger.info("Received keys: %s, values: %s", keys, values) count += 1 if count % 1000 == 0: logger.info("count: %s", count) except Exception: logger.error("Failed to check: %s", traceback.format_exc()) await asyncio.sleep(1)
def __on_connected(self): logger.info("Connected to endpoint: %s", self.__endpoint) self.notify(Event.ON_CONNECTED)
import asyncio import pycommons.logger from maxwell.client import Client logger = pycommons.logger.get_instance(__name__) if __name__ == '__main__': loop = asyncio.get_event_loop() client = Client(["localhost:8081", "localhost:8082"], loop=loop) master = client.get_master() endpoint = loop.run_until_complete( asyncio.ensure_future(master.resolve_frontend())) logger.info("endpoint: %s", endpoint) endpoint = loop.run_until_complete( asyncio.ensure_future(master.resolve_backend("topic_0"))) logger.info("endpoint: %s", endpoint) loop.run_forever()