Move @with_monitor_paused decoartor to directory_monitor.py

This commit is contained in:
Kristóf Tóth 2018-03-21 17:18:16 +01:00
parent 1a4d88668a
commit 095c818a36
2 changed files with 13 additions and 11 deletions

View File

@ -1,5 +1,6 @@
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler as FileSystemWatchdogEventHandler
from functools import wraps
from tfw.networking.event_handlers.server_connector import ServerUplinkConnector
from tfw.components.decorators import RateLimiter
@ -65,3 +66,13 @@ class WebideReloadWatchdogEventHandler(FileSystemWatchdogEventHandler):
log.debug(event)
key = 'webide'
self.uplink.send(key, {'data': {'command': 'reload'}})
def with_monitor_paused(fun):
@wraps(fun)
def wrapper(self, *args, **kwargs):
if self.monitor:
with self.monitor.pauser:
return fun(self, *args, **kwargs)
return fun(self, *args, **kwargs)
return wrapper

View File

@ -1,8 +1,8 @@
from functools import wraps
from xmlrpc.client import Fault as SupervisorFault
from tfw.event_handler_base import TriggerlessEventHandler
from tfw.components.mixins import SupervisorMixin
from tfw.components.directory_monitor import with_monitor_paused
from tfw.config.logs import logging
log = logging.getLogger(__name__)
@ -25,16 +25,7 @@ class ProcessManagingEventHandler(TriggerlessEventHandler):
self.monitor = dirmonitor
self.processmanager = ProcessManager()
def _with_monitor_paused(fun):
@wraps(fun)
def wrapper(self, *args, **kwargs):
if self.monitor:
with self.monitor.pauser:
return fun(self, *args, **kwargs)
return fun(self, *args, **kwargs)
return wrapper
@_with_monitor_paused
@with_monitor_paused
def handle_event(self, key, message):
try:
data = message['data']