Extract process managing logic to SupervisorMixin from event handlers

This commit is contained in:
Kristóf Tóth
2018-02-06 15:34:43 +01:00
parent 8b9f7e50cb
commit c74c00c618
3 changed files with 17 additions and 9 deletions

View File

@ -1,4 +1,6 @@
import xmlrpc.client, zmq
from contextlib import suppress
from xmlrpc.client import Fault as SupervisorFault
from .config.envvars import SUPERVISOR_HTTP_URI
@ -14,6 +16,17 @@ def create_source_code_response_data(filename, content, language):
class SupervisorMixin:
supervisor = xmlrpc.client.ServerProxy(SUPERVISOR_HTTP_URI).supervisor
def stop_process(self):
with suppress(SupervisorFault):
self.supervisor.stopProcess(self.process_name)
def start_process(self):
self.supervisor.startProcess(self.process_name)
def restart_process(self):
self.stop_process()
self.start_process()
class ZMQConnectorBase:
def __init__(self, zmq_context=None):