From c2871d94ed66b1b9387e42fd5531b36be0eefede Mon Sep 17 00:00:00 2001 From: Arksine Date: Sat, 20 Mar 2021 06:10:18 -0400 Subject: [PATCH] file_manager: remove gcode metadata prune callback Inotify keeps metadata in sync with the file system. Signed-off-by: Eric Callahan --- moonraker/components/file_manager.py | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/moonraker/components/file_manager.py b/moonraker/components/file_manager.py index 7f54126..01d6695 100644 --- a/moonraker/components/file_manager.py +++ b/moonraker/components/file_manager.py @@ -11,7 +11,7 @@ import logging import json import tempfile from concurrent.futures import ThreadPoolExecutor -from tornado.ioloop import IOLoop, PeriodicCallback +from tornado.ioloop import IOLoop from tornado.locks import Event from inotify_simple import INotify from inotify_simple import flags as iFlags @@ -604,7 +604,6 @@ class FileManager: def close(self): self.inotify_handler.close() - self.gcode_metadata.close() INOTIFY_DELETE_TIME = .25 @@ -946,7 +945,6 @@ class INotifyHandler: pass -METADATA_PRUNE_TIME = 600000 METADATA_NAMESPACE = "gcode_metadata" METADATA_VERSION = 3 @@ -968,21 +966,20 @@ class MetadataStorage: self.events = {} self.busy = False self.gc_path = gc_path - self.prune_cb = PeriodicCallback( - self.prune_metadata, METADATA_PRUNE_TIME) if self.gc_path: - self.prune_cb.start() + # Check for removed gcode files while moonraker was shutdown + for fname in list(self.mddb.keys()): + fpath = os.path.join(self.gc_path, fname) + if not os.path.isfile(fpath): + self.remove_file_metadata(fname) + logging.info(f"Pruned file: {fname}") + continue def update_gcode_path(self, path): if path == self.gc_path: return self.mddb.clear() self.gc_path = path - if not self.prune_cb.is_running(): - self.prune_cb.start() - - def close(self): - self.prune_cb.stop() def get(self, key, default=None): return self.mddb.get(key, default) @@ -990,14 +987,6 @@ class MetadataStorage: def __getitem__(self, key): return self.mddb[key] - def prune_metadata(self): - for fname in list(self.mddb.keys()): - fpath = os.path.join(self.gc_path, fname) - if not os.path.isfile(fpath): - self.remove_file_metadata(fname) - logging.info(f"Pruned file: {fname}") - continue - def _has_valid_data(self, fname, fsize, modified): mdata = self.mddb.get(fname, {'size': "", 'modified': 0}) return mdata['size'] == fsize and mdata['modified'] == modified