mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-12-23 07:31:57 +00:00
Implement pausing watchdog while webide files are being written
This commit is contained in:
parent
516c5746f8
commit
0b3db0ae9e
@ -12,9 +12,17 @@ class WebideReloadEventHandler(FileSystemEventHandler):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.uplink = ServerUplinkConnector()
|
||||
self._paused = False
|
||||
|
||||
def pause(self):
|
||||
self._paused = True
|
||||
|
||||
def resume(self):
|
||||
self._paused = False
|
||||
|
||||
@RateLimiter(rate_per_second=5)
|
||||
def on_modified(self, event):
|
||||
if self._paused: return
|
||||
log.debug(event)
|
||||
anchor = 'anchor_webide'
|
||||
self.uplink.send(anchor, {'anchor': anchor,
|
||||
@ -24,7 +32,9 @@ class WebideReloadEventHandler(FileSystemEventHandler):
|
||||
class DirectoryMonitor:
|
||||
def __init__(self, directory):
|
||||
self.observer = Observer()
|
||||
self.observer.schedule(WebideReloadEventHandler(), directory, recursive=True)
|
||||
self.eventhandler = WebideReloadEventHandler()
|
||||
self.observer.schedule(self.eventhandler, directory, recursive=True)
|
||||
self.pause, self.resume = self.eventhandler.pause, self.eventhandler.resume
|
||||
|
||||
def watch(self):
|
||||
self.observer.start()
|
||||
|
@ -68,9 +68,11 @@ class SourceCodeEventHandler(EventHandlerBase, SupervisorMixin):
|
||||
return data
|
||||
|
||||
def write(self, data):
|
||||
self.monitor.pause()
|
||||
try: self.filemanager.file_contents = data['content']
|
||||
except Exception: log.exception('Error writing file!')
|
||||
self.restart_process()
|
||||
self.monitor.resume()
|
||||
return data
|
||||
|
||||
def select(self, data):
|
||||
|
Loading…
Reference in New Issue
Block a user