Refactor supervisor logging logic to separate mixin

This commit is contained in:
Kristóf Tóth 2018-05-28 14:32:11 +02:00
parent fd56f8ca63
commit 44df95a434
3 changed files with 12 additions and 8 deletions

View File

@ -4,14 +4,14 @@
from xmlrpc.client import Fault as SupervisorFault
from tfw import EventHandlerBase
from tfw.mixins import SupervisorMixin
from tfw.mixins import SupervisorMixin, SupervisorLogMixin
from tfw.config.logs import logging
from .directory_monitor import with_monitor_paused
LOG = logging.getLogger(__name__)
class ProcessManager(SupervisorMixin):
class ProcessManager(SupervisorMixin, SupervisorLogMixin):
def __init__(self):
self.commands = {'start': self.start_process,
'stop': self.stop_process,

View File

@ -1,7 +1,7 @@
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
# All Rights Reserved. See LICENSE file for details.
from .supervisor_mixin import SupervisorMixin
from .supervisor_mixin import SupervisorMixin, SupervisorLogMixin
from .callback_mixin import CallbackMixin
from .observer_mixin import ObserverMixin
from .monitor_manager_mixin import MonitorManagerMixin

View File

@ -9,9 +9,11 @@ from os import remove
from tfw.config import TFWENV
class SupervisorMixin:
class SupervisorBaseMixin:
supervisor = xmlrpc.client.ServerProxy(TFWENV.SUPERVISOR_HTTP_URI).supervisor
class SupervisorMixin(SupervisorBaseMixin):
def stop_process(self, process_name):
with suppress(SupervisorFault):
self.supervisor.stopProcess(process_name)
@ -19,6 +21,12 @@ class SupervisorMixin:
def start_process(self, process_name):
self.supervisor.startProcess(process_name)
def restart_process(self, process_name):
self.stop_process(process_name)
self.start_process(process_name)
class SupervisorLogMixin(SupervisorBaseMixin):
def read_log_stdout(self, process_name):
return self._read_log_internal(self.supervisor.readProcessStdoutLog, process_name)
@ -34,7 +42,3 @@ class SupervisorMixin:
for logfile in ('stdout_logfile', 'stderr_logfile'):
remove(self.supervisor.getProcessInfo(process_name)[logfile])
self.supervisor.clearProcessLogs(process_name)
def restart_process(self, process_name):
self.stop_process(process_name)
self.start_process(process_name)