mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 14:31:32 +00:00
Refactor solvable responses
This commit is contained in:
parent
e04cc08dd6
commit
6f785b3ca7
@ -12,21 +12,29 @@ class TFWServer:
|
||||
[(r'/ws', FSMManagingSocketHandler, {'fsm': self.fsm})]
|
||||
)
|
||||
self.controller_connector = ControllerConnector()
|
||||
self.controller_connector.register_callback(self.zmq_callback)
|
||||
self.controller_connector.register_callback(self.handle_controller_request)
|
||||
self.controller_request_handlers = {
|
||||
'solution_check': self.handle_solution_check_request,
|
||||
'test': self.handle_test_request
|
||||
}
|
||||
|
||||
@property
|
||||
def fsm(self):
|
||||
return self._fsm
|
||||
|
||||
def zmq_callback(self, stream, msg_parts):
|
||||
def handle_controller_request(self, stream, msg_parts):
|
||||
key, data = deserialize_all(*msg_parts)
|
||||
if key == 'test':
|
||||
stream.send_multipart(serialize_all(key, 'OK'))
|
||||
if key == 'solution_check':
|
||||
stream.send_multipart(serialize_all(key, {
|
||||
'solved': self.fsm.is_solved(),
|
||||
'message': 'solved' if self.fsm.is_solved() else 'not solved'
|
||||
}))
|
||||
response = self.controller_request_handlers[key](data)
|
||||
stream.send_multipart(serialize_all(key, response))
|
||||
|
||||
def handle_test_request(self, data):
|
||||
return 'OK'
|
||||
|
||||
def handle_solution_check_request(self, data):
|
||||
return {
|
||||
'solved': self.fsm.is_solved(),
|
||||
'message': 'solved' if self.fsm.is_solved() else 'not solved'
|
||||
}
|
||||
|
||||
def listen(self, port):
|
||||
self.application.listen(port)
|
||||
|
Loading…
Reference in New Issue
Block a user