Move SupervisorMixin to mixins

This commit is contained in:
Bálint Bokros 2018-02-13 17:51:19 +01:00
parent f5a8230d3b
commit 14f3a4a153
5 changed files with 23 additions and 22 deletions

View File

@ -0,0 +1 @@
from .supervisor_mixin import SupervisorMixin

View 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()

View File

@ -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

View File

@ -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__)

View File

@ -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)