1
0
mirror of https://github.com/avatao-content/test-tutorial-framework synced 2024-11-15 04:27:18 +00:00
test-tutorial-framework/controller/opt/server.py

38 lines
1.0 KiB
Python
Raw Normal View History

import os
import json
from tornado.ioloop import IOLoop
from tornado.web import RequestHandler, Application
2019-07-24 13:52:38 +00:00
from tfw.event_handlers import FSMAwareEventHandler
from tfw.main import EventHandlerFactory, setup_signal_handlers
class ControllerPostHandler(RequestHandler):
2019-07-12 21:26:57 +00:00
# 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({
2018-07-24 15:17:14 +00:00
'solved': self.controller.fsm_in_accepted_state
}))
if __name__ == '__main__':
2019-07-24 13:52:38 +00:00
controller_eh = EventHandlerFactory().build(
lambda *_: None,
event_handler_type=FSMAwareEventHandler
)
2019-07-12 21:26:57 +00:00
application = Application([(
f'/{os.environ["SECRET"]}',
ControllerPostHandler,
2019-07-24 13:52:38 +00:00
{'controller': controller_eh}
)])
application.listen(os.environ['CONTROLLER_PORT'])
2019-07-24 13:52:38 +00:00
setup_signal_handlers()
IOLoop.instance().start()