Refactor EventHandles supervisord access to a mixin

This commit is contained in:
Kristóf Tóth 2018-01-24 12:17:15 +01:00
parent 3a7349abd4
commit 2b306efb04
2 changed files with 10 additions and 9 deletions

View File

@ -1,4 +1,6 @@
import json
import json, xmlrpc.client
from config.envvars import SUPERVISOR_HTTP_URI
def parse_anchor_from_message(message):
@ -12,3 +14,6 @@ def create_source_code_response_data(filename, content, language):
'content': content,
'language': language
}
class SupervisorMixin:
supervisor = xmlrpc.client.ServerProxy(SUPERVISOR_HTTP_URI).supervisor

View File

@ -1,13 +1,12 @@
import json
from shutil import copy, rmtree, copytree
from os.path import splitext
import xmlrpc.client
from config import SUPERVISOR_HTTP_URI, LOGIN_APP_DIR
from util import SupervisorMixin
from config import LOGIN_APP_DIR
from event_handler_base import EventHandlerBase
class SourceCodeEventHandler(EventHandlerBase):
class SourceCodeEventHandler(EventHandlerBase, SupervisorMixin):
def __init__(self, anchor, filename, process_name=None, zmq_context=None):
super().__init__(anchor, zmq_context)
self.working_directory = LOGIN_APP_DIR
@ -19,9 +18,6 @@ class SourceCodeEventHandler(EventHandlerBase):
'write': self.write_file
}
server = xmlrpc.client.ServerProxy(SUPERVISOR_HTTP_URI)
self.supervisor = server.supervisor
self.file = self.create_initial_state()
def handle_event(self, anchor, data_json):