Implement DirectoryMonitor support in ProcessManagingEventHandler

This commit is contained in:
Kristóf Tóth 2018-03-02 10:21:56 +01:00
parent feb946a1bb
commit e451de2179

View File

@ -1,3 +1,5 @@
from functools import wraps
from tfw.event_handler_base import TriggerlessEventHandler
from tfw.components.mixins import SupervisorMixin
from tfw.networking.event_handlers.server_connector import ServerUplinkConnector
@ -16,12 +18,23 @@ class ProcessManager(SupervisorMixin):
class ProcessManagingEventHandler(TriggerlessEventHandler):
def __init__(self, key):
def __init__(self, key, dirmonitor=None):
super().__init__(key)
self.key = key
self.monitor = dirmonitor
self.processmanager = ProcessManager()
self.uplink = ServerUplinkConnector()
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
def handle_event(self, key, data_json):
data = data_json['data']
self.processmanager(data['command'], data['process_name'])