Improve tornado parallel

pull/46/head
Raphaël Vinot 2016-08-23 18:02:29 +02:00
parent 6ba2731eb5
commit d6388e1c52
1 changed files with 13 additions and 5 deletions

View File

@ -166,15 +166,23 @@ class ListModules(tornado.web.RequestHandler):
self.write(json.dumps(ret))
@tornado.gen.coroutine
def async_module(request, write_fct):
jsonpayload = request.body.decode('utf-8')
x = json.loads(jsonpayload)
log.debug('MISP QueryModule request {0}'.format(jsonpayload))
ret = mhandlers[x['module']].handler(q=jsonpayload)
write_fct(json.dumps(ret))
class QueryModule(tornado.web.RequestHandler):
@tornado.gen.coroutine
def post(self):
global mhandlers
jsonpayload = self.request.body.decode('utf-8')
x = json.loads(jsonpayload)
log.debug('MISP QueryModule request {0}'.format(jsonpayload))
ret = mhandlers[x['module']].handler(q=jsonpayload)
self.write(json.dumps(ret))
try:
yield async_module(self.request, self.write)
except Exception:
log.exception("Someting bad happened.")
def main():