mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 17:21:31 +00:00
Refactor supervisor logging logic to separate mixin
This commit is contained in:
parent
fd56f8ca63
commit
44df95a434
@ -4,14 +4,14 @@
|
|||||||
from xmlrpc.client import Fault as SupervisorFault
|
from xmlrpc.client import Fault as SupervisorFault
|
||||||
|
|
||||||
from tfw import EventHandlerBase
|
from tfw import EventHandlerBase
|
||||||
from tfw.mixins import SupervisorMixin
|
from tfw.mixins import SupervisorMixin, SupervisorLogMixin
|
||||||
from tfw.config.logs import logging
|
from tfw.config.logs import logging
|
||||||
from .directory_monitor import with_monitor_paused
|
from .directory_monitor import with_monitor_paused
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ProcessManager(SupervisorMixin):
|
class ProcessManager(SupervisorMixin, SupervisorLogMixin):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.commands = {'start': self.start_process,
|
self.commands = {'start': self.start_process,
|
||||||
'stop': self.stop_process,
|
'stop': self.stop_process,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
|
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
|
||||||
# All Rights Reserved. See LICENSE file for details.
|
# 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 .callback_mixin import CallbackMixin
|
||||||
from .observer_mixin import ObserverMixin
|
from .observer_mixin import ObserverMixin
|
||||||
from .monitor_manager_mixin import MonitorManagerMixin
|
from .monitor_manager_mixin import MonitorManagerMixin
|
||||||
|
@ -9,9 +9,11 @@ from os import remove
|
|||||||
from tfw.config import TFWENV
|
from tfw.config import TFWENV
|
||||||
|
|
||||||
|
|
||||||
class SupervisorMixin:
|
class SupervisorBaseMixin:
|
||||||
supervisor = xmlrpc.client.ServerProxy(TFWENV.SUPERVISOR_HTTP_URI).supervisor
|
supervisor = xmlrpc.client.ServerProxy(TFWENV.SUPERVISOR_HTTP_URI).supervisor
|
||||||
|
|
||||||
|
|
||||||
|
class SupervisorMixin(SupervisorBaseMixin):
|
||||||
def stop_process(self, process_name):
|
def stop_process(self, process_name):
|
||||||
with suppress(SupervisorFault):
|
with suppress(SupervisorFault):
|
||||||
self.supervisor.stopProcess(process_name)
|
self.supervisor.stopProcess(process_name)
|
||||||
@ -19,6 +21,12 @@ class SupervisorMixin:
|
|||||||
def start_process(self, process_name):
|
def start_process(self, process_name):
|
||||||
self.supervisor.startProcess(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):
|
def read_log_stdout(self, process_name):
|
||||||
return self._read_log_internal(self.supervisor.readProcessStdoutLog, 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'):
|
for logfile in ('stdout_logfile', 'stderr_logfile'):
|
||||||
remove(self.supervisor.getProcessInfo(process_name)[logfile])
|
remove(self.supervisor.getProcessInfo(process_name)[logfile])
|
||||||
self.supervisor.clearProcessLogs(process_name)
|
self.supervisor.clearProcessLogs(process_name)
|
||||||
|
|
||||||
def restart_process(self, process_name):
|
|
||||||
self.stop_process(process_name)
|
|
||||||
self.start_process(process_name)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user