2018-01-24 14:10:59 +00:00
|
|
|
from shutil import rmtree, copytree
|
2018-01-24 14:54:03 +00:00
|
|
|
from xmlrpc.client import Fault as SupervisorFault
|
2018-01-17 15:33:34 +00:00
|
|
|
|
2018-01-24 14:10:59 +00:00
|
|
|
from event_handler_base import EventHandlerBase
|
|
|
|
from util import SupervisorMixin
|
|
|
|
from config import TERMINADO_DIR
|
2018-01-17 15:33:34 +00:00
|
|
|
|
|
|
|
|
2018-01-24 14:10:59 +00:00
|
|
|
class TerminadoEventHandler(EventHandlerBase, SupervisorMixin):
|
|
|
|
def __init__(self, anchor, process_name, zmq_context=None):
|
2018-01-17 15:33:34 +00:00
|
|
|
super().__init__(anchor, zmq_context)
|
2018-01-24 14:10:59 +00:00
|
|
|
self.working_directory = TERMINADO_DIR
|
|
|
|
self.process_name = process_name
|
|
|
|
self.setup_terminado_server()
|
|
|
|
|
|
|
|
def setup_terminado_server(self):
|
|
|
|
rmtree(self.working_directory, ignore_errors=True)
|
|
|
|
copytree('terminado_server/', self.working_directory)
|
|
|
|
self.supervisor.startProcess(self.process_name)
|
2018-01-17 15:33:34 +00:00
|
|
|
|
|
|
|
def handle_event(self, anchor, data_json):
|
|
|
|
raise NotImplementedError # TODO: wat do?
|
2018-01-24 14:54:03 +00:00
|
|
|
|
|
|
|
def handle_reset(self, data_json):
|
|
|
|
try: self.supervisor.stopProcess(self.process_name)
|
|
|
|
except SupervisorFault: pass
|
|
|
|
self.supervisor.startProcess(self.process_name)
|