import os import json from tornado.ioloop import IOLoop from tornado.web import RequestHandler, Application from tfw.builtins import FSMAwareEventHandler from tfw.main import EventHandlerFactory class ControllerPostHandler(RequestHandler): # pylint: disable=abstract-method,attribute-defined-outside-init,unused-argument def initialize(self, **kwargs): self.controller = kwargs['controller'] def post(self, *args, **kwargs): self.set_header('Content-Type', 'application/json') self.write(json.dumps({ 'solved': self.controller.fsm_in_accepted_state })) class ControllerEventHandler(FSMAwareEventHandler): def handle_event(self, message): pass if __name__ == '__main__': controller = ControllerEventHandler('controller') controller_eh = EventHandlerFactory().build(controller) application = Application([( f'/{os.environ["SECRET"]}', ControllerPostHandler, {'controller': controller} )]) application.listen(os.environ['CONTROLLER_PORT']) try: IOLoop.instance().start() finally: controller.cleanup()