def __call__(self):
tm = get_tm(self.request)
await tm.abort(self.request)
ws = web.WebSocketResponse()
await ws.prepare(self.request)
async for msg in ws:
if msg.tp == aiohttp.WSMsgType.text:
message = ujson.loads(msg.data)
if message['op'] == 'close':
await ws.close()
elif message['op'] == 'GET':
txn = await tm.begin(request=self.request)
try:
await self.handle_ws_request(ws, message)
except Exception:
await ws.close()
raise
finally:
# only currently support GET requests which are *never*
# supposed to be commits
await tm.abort(txn=txn)
else:
await ws.close()
elif msg.tp == aiohttp.WSMsgType.error:
logger.debug('ws connection closed with exception {0:s}'
.format(ws.exception()))
logger.debug('websocket connection closed')
return {}
评论列表
文章目录