Add support for stopping/starting ProcessLogHandler from API

This commit is contained in:
Kristóf Tóth 2019-12-19 16:21:15 +01:00
parent c8d4080ef5
commit 9481e8f921

View File

@ -16,10 +16,13 @@ class ProcessLogHandler:
self._initial_log_tail = log_tail self._initial_log_tail = log_tail
self.command_handlers = { self.command_handlers = {
'process.log.set': self.handle_set 'process.log.set': self.handle_set,
'process.log.start': self.handle_start,
'process.log.stop': self.handle_stop
} }
def start(self): def start(self):
if not self._monitor:
self._monitor = LogInotifyObserver( self._monitor = LogInotifyObserver(
connector=self.connector, connector=self.connector,
process_name=self.process_name, process_name=self.process_name,
@ -40,5 +43,16 @@ class ProcessLogHandler:
if data.get('tail'): if data.get('tail'):
self._monitor.log_tail = data['tail'] self._monitor.log_tail = data['tail']
def cleanup(self): def handle_start(self, _):
self.start()
def handle_stop(self, _):
self._stop_monitor()
def _stop_monitor(self):
if self._monitor:
self._monitor.stop() self._monitor.stop()
self._monitor = None
def cleanup(self):
self._stop_monitor()