mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-23 00:21:32 +00:00
Move SupervisorMixin to mixins
This commit is contained in:
parent
f5a8230d3b
commit
14f3a4a153
1
lib/tfw/components/mixins/__init__.py
Normal file
1
lib/tfw/components/mixins/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from .supervisor_mixin import SupervisorMixin
|
20
lib/tfw/components/mixins/supervisor_mixin.py
Normal file
20
lib/tfw/components/mixins/supervisor_mixin.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import xmlrpc.client
|
||||||
|
from contextlib import suppress
|
||||||
|
from xmlrpc.client import Fault as SupervisorFault
|
||||||
|
|
||||||
|
from tfw.config import tfwenv
|
||||||
|
|
||||||
|
|
||||||
|
class SupervisorMixin:
|
||||||
|
supervisor = xmlrpc.client.ServerProxy(tfwenv.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()
|
@ -1,7 +1,7 @@
|
|||||||
from os.path import splitext, isfile, join, relpath
|
from os.path import splitext, isfile, join, relpath
|
||||||
from glob import glob
|
from glob import glob
|
||||||
|
|
||||||
from tfw.util import SupervisorMixin
|
from tfw.components.mixins import SupervisorMixin
|
||||||
from tfw.event_handler_base import EventHandlerBase
|
from tfw.event_handler_base import EventHandlerBase
|
||||||
from tfw.components.directory_monitor import DirectoryMonitor
|
from tfw.components.directory_monitor import DirectoryMonitor
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from tfw.event_handler_base import EventHandlerBase
|
from tfw.event_handler_base import EventHandlerBase
|
||||||
from tfw.util import SupervisorMixin
|
from tfw.components.mixins import SupervisorMixin
|
||||||
from tfw.config import tfwenv
|
from tfw.config import tfwenv
|
||||||
from tfw.config.logs import logging
|
from tfw.config.logs import logging
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
import xmlrpc.client
|
|
||||||
from contextlib import suppress
|
|
||||||
from xmlrpc.client import Fault as SupervisorFault
|
|
||||||
from time import time, sleep
|
from time import time, sleep
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
from tfw.config import tfwenv
|
|
||||||
|
|
||||||
|
|
||||||
def create_source_code_response_data(filename, content, language):
|
def create_source_code_response_data(filename, content, language):
|
||||||
return {
|
return {
|
||||||
@ -15,21 +10,6 @@ def create_source_code_response_data(filename, content, language):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class SupervisorMixin:
|
|
||||||
supervisor = xmlrpc.client.ServerProxy(tfwenv.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 RateLimiter:
|
class RateLimiter:
|
||||||
def __init__(self, rate_per_second):
|
def __init__(self, rate_per_second):
|
||||||
self.min_interval = 1 / float(rate_per_second)
|
self.min_interval = 1 / float(rate_per_second)
|
||||||
|
Loading…
Reference in New Issue
Block a user