mirror of
				https://github.com/avatao-content/test-tutorial-framework
				synced 2025-11-04 09:32:56 +00:00 
			
		
		
		
	Implement TFW controller after months of pain and suffering ¯\_(ツ)_/¯
This commit is contained in:
		
							
								
								
									
										39
									
								
								controller/opt/server.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								controller/opt/server.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
			
		||||
import os
 | 
			
		||||
import json
 | 
			
		||||
 | 
			
		||||
from tornado.ioloop import IOLoop
 | 
			
		||||
from tornado.web import RequestHandler, Application
 | 
			
		||||
 | 
			
		||||
from tfw import FSMAwareEventHandler
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ControllerPostHandler(RequestHandler):
 | 
			
		||||
    # pylint: disable=abstract-method
 | 
			
		||||
    def initialize(self, **kwargs): # pylint: disable=arguments-differ
 | 
			
		||||
        self.controller = kwargs['controller']
 | 
			
		||||
 | 
			
		||||
    def post(self, *args, **kwargs):
 | 
			
		||||
        self.set_header('Content-Type', 'application/json')
 | 
			
		||||
        self.write(json.dumps({
 | 
			
		||||
            'solved': self.controller.in_accepted_state
 | 
			
		||||
        }))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ControllerEventHandler(FSMAwareEventHandler):
 | 
			
		||||
    def handle_event(self, message):
 | 
			
		||||
        pass
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    controller = ControllerEventHandler('controller')
 | 
			
		||||
    application = Application([(
 | 
			
		||||
        f'/{os.environ["SECRET"]}',
 | 
			
		||||
        ControllerPostHandler,
 | 
			
		||||
        {'controller': controller}
 | 
			
		||||
    )])
 | 
			
		||||
    application.listen(os.environ['CONTROLLER_PORT'])
 | 
			
		||||
 | 
			
		||||
    try:
 | 
			
		||||
        IOLoop.instance().start()
 | 
			
		||||
    finally:
 | 
			
		||||
        controller.cleanup()
 | 
			
		||||
		Reference in New Issue
	
	Block a user