mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 14:31:32 +00:00
Make controller async
This commit is contained in:
parent
86aecd18a8
commit
cb46a8b80e
14
lib/tfw/networking/async_solvable_connector.py
Normal file
14
lib/tfw/networking/async_solvable_connector.py
Normal file
@ -0,0 +1,14 @@
|
||||
from tfw.networking.serialization import deserialize_all
|
||||
from tfw.networking.solvable_connector import SolvableConnector
|
||||
|
||||
|
||||
class AsyncSolvableConnector(SolvableConnector):
|
||||
def __init__(self, async_zmq_context=None):
|
||||
if async_zmq_context is None:
|
||||
from zmq.eventloop.future import Context
|
||||
async_zmq_context = Context.instance()
|
||||
super(AsyncSolvableConnector, self).__init__(async_zmq_context)
|
||||
|
||||
async def recv(self):
|
||||
response = await self._zmq_req_socket.recv_multipart()
|
||||
return deserialize_all(*response)
|
@ -4,13 +4,13 @@ from tornado.web import Application
|
||||
from tao.config import taoenv
|
||||
from tfw.config import tfwenv
|
||||
from handlers import SolutionCheckHandler, TestHandler
|
||||
from tfw.networking.solvable_connector import SolvableConnector
|
||||
from tfw.networking.async_solvable_connector import AsyncSolvableConnector
|
||||
|
||||
from tfw.config.logs import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
if __name__ == '__main__':
|
||||
solvable_connector = SolvableConnector()
|
||||
solvable_connector = AsyncSolvableConnector()
|
||||
routes = [
|
||||
(r'/{secret}/?'.format(secret=taoenv.SECRET), SolutionCheckHandler, {'solvable_connector': solvable_connector}),
|
||||
(r'/{secret}/test/?'.format(secret=taoenv.SECRET), TestHandler, {'solvable_connector': solvable_connector})
|
||||
|
@ -7,9 +7,9 @@ class SolutionCheckHandler(RequestHandler):
|
||||
def initialize(self, solvable_connector):
|
||||
self.solvable_connector = solvable_connector
|
||||
|
||||
def get(self):
|
||||
async def get(self):
|
||||
log.debug('Sending request to solvable')
|
||||
self.solvable_connector.send('solution_check', {})
|
||||
resp_key, resp_data = self.solvable_connector.recv()
|
||||
resp_key, resp_data = await self.solvable_connector.recv()
|
||||
log.debug('Received answer from solvable')
|
||||
self.write(resp_data)
|
||||
|
@ -5,7 +5,7 @@ class TestHandler(RequestHandler):
|
||||
def initialize(self, solvable_connector):
|
||||
self.solvable_connector = solvable_connector
|
||||
|
||||
def get(self):
|
||||
async def get(self):
|
||||
self.solvable_connector.send('test', {})
|
||||
resp_key, resp_data = self.solvable_connector.recv()
|
||||
resp_key, resp_data = await self.solvable_connector.recv()
|
||||
self.write(resp_data)
|
||||
|
Loading…
Reference in New Issue
Block a user