Improve webide refresh trigger rate limiting

This commit is contained in:
Kristóf Tóth 2018-02-13 14:37:56 +01:00
parent dceb4b2b7e
commit 4d49c8d11b

View File

@ -1,4 +1,4 @@
from time import time from time import time, sleep
from watchdog.observers import Observer from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler from watchdog.events import FileSystemEventHandler
@ -17,7 +17,7 @@ class WebideReloadEventHandler(FileSystemEventHandler):
self.last_call = time() self.last_call = time()
def on_modified(self, event): def on_modified(self, event):
if self.limit_rate(): return self.limit_rate()
log.debug(event) log.debug(event)
anchor = 'anchor_webide' anchor = 'anchor_webide'
@ -28,7 +28,8 @@ class WebideReloadEventHandler(FileSystemEventHandler):
since_last_call = time() - self.last_call since_last_call = time() - self.last_call
to_next_call = self.min_interval - since_last_call to_next_call = self.min_interval - since_last_call
self.last_call = time() self.last_call = time()
return to_next_call > 0 if to_next_call > 0:
sleep(to_next_call)
class DirectoryMonitor: class DirectoryMonitor: