Skip to content

Commit

Permalink
Improve tornado parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafiot committed Aug 23, 2016
1 parent 6ba2731 commit d6388e1
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions misp_modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,23 @@ def get(self):
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():
Expand Down

0 comments on commit d6388e1

Please sign in to comment.