async def handle(request): if False: log_peer(request) ws = web.WebSocketResponse() await ws.prepare(request) jh = JournalHandler(ws) async for msg in ws: if msg.type == aiohttp.WSMsgType.TEXT: if msg.data == 'close': await ws.close() return ws elif msg.data == 'start-irq-update': await jh.start_irq_update() else: log.debug("unknown websocket command {}".format(str(msg.data))) elif msg.type == aiohttp.WSMsgType.ERROR: log.warning('ws connection closed with exception %s' % ws.exception()) break elif msg.type == aiohttp.WSMsgType.CLOSED: log.warning('ws connection closed') break else: log.warning('ws unknown command') break await ws.close() return ws
def log_peer(request): peername = request.transport.get_extra_info('peername') if peername: host, port = peername[0:2] else: host = port = "unknown" log.debug("web journal socket request from {}[{}]".format(host, port))
async def handle(request): if False: log_peer(request) ws = web.WebSocketResponse() await ws.prepare(request) jh = JournalHandler(ws) async for msg in ws: if msg.type == aiohttp.WSMsgType.TEXT: if msg.data == 'close': await ws.close() return ws elif msg.data == 'start-process-update': await jh.sync_info() else: log.debug("unknown websocket command {}".format(str(msg.data))) elif msg.type == aiohttp.WSMsgType.ERROR: break elif msg.type == aiohttp.WSMsgType.CLOSED: break else: break await ws.close() return ws
async def handle(request): if False: log_peer(request) ws = web.WebSocketResponse() await ws.prepare(request) jh = JournalHandler(ws) async for msg in ws: if msg.type == aiohttp.WSMsgType.TEXT: if msg.data == 'close': await ws.close() await jh.shutdown() return ws elif msg.data == 'history': await jh.sync_history() elif msg.data == 'journal-sync-start': jh.sync_log() elif msg.data == 'journal-sync-stop': jh.journal_sync_stop() else: log.debug("unknown websocket command {}".format(str(msg.data))) elif msg.type == aiohttp.WSMsgType.ERROR: print('ws connection closed with exception %s' % ws.exception()) return ws
def register_timeout_handler_daily(app): loop = asyncio.get_event_loop() midnight_sec = seconds_to_midnight() call_time = loop.time() + midnight_sec msg = "Register daily timeout [scheduled in {} seconds]".format(call_time) log.debug(msg) loop.call_at(call_time, register_timeout_handler_daily, app) timeout_daily_midnight(app)
async def handle(request): peername = request.transport.get_extra_info('peername') host = port = "unknown" if peername is not None: host, port = peername[0:2] log.debug("web resource socket request from {}[{}]".format(host, port)) ws = web.WebSocketResponse() await ws.prepare(request) jh = ResourceHandler(ws) async for msg in ws: if msg.type == aiohttp.WSMsgType.TEXT: if msg.data == 'close': await ws.close() await jh.shutdown() return ws elif msg.data == 'start-cpu-utilization': jh.sync_cpu_usage() elif msg.data == 'start-process-utilization': jh.sync_process_utilization() elif msg.data == 'get-meminfo': jh.get_meminfo() else: log.debug("unknown websocket command: {}".format(msg.data)) elif msg.type == aiohttp.WSMsgType.ERROR: print('ws connection closed with exception %s' % ws.exception()) elif msg.type == aiohttp.WSMsgType.CLOSED: print('ws closed') else: print('ws: unknown') await ws.close() await jh.shutdown() return ws
def timeout_daily_midnight(app): log.debug("Execute daily execution handler") start_time = time.time() # do something end_time = time.time() log.debug("Excuted in {:0.2f} seconds".format(end_time - start_time))