refactor: Disable file monitoring functionality with ENABLE_FILE_MONITORING flag

This commit is contained in:
Will Miao
2025-04-12 06:47:47 +08:00
parent 0618541527
commit 9277d8d8f8
3 changed files with 33 additions and 10 deletions

View File

@@ -12,6 +12,9 @@ from .service_registry import ServiceRegistry
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
# Configuration constant to control file monitoring functionality
ENABLE_FILE_MONITORING = False
class BaseFileHandler(FileSystemEventHandler): class BaseFileHandler(FileSystemEventHandler):
"""Base handler for file system events""" """Base handler for file system events"""
@@ -404,6 +407,10 @@ class BaseFileMonitor:
def start(self): def start(self):
"""Start file monitoring""" """Start file monitoring"""
if not ENABLE_FILE_MONITORING:
logger.info("File monitoring is disabled via ENABLE_FILE_MONITORING setting")
return
for path in self.monitor_paths: for path in self.monitor_paths:
try: try:
self.observer.schedule(self.handler, path, recursive=True) self.observer.schedule(self.handler, path, recursive=True)
@@ -415,11 +422,17 @@ class BaseFileMonitor:
def stop(self): def stop(self):
"""Stop file monitoring""" """Stop file monitoring"""
if not ENABLE_FILE_MONITORING:
return
self.observer.stop() self.observer.stop()
self.observer.join() self.observer.join()
def rescan_links(self): def rescan_links(self):
"""Rescan links when new ones are added""" """Rescan links when new ones are added"""
if not ENABLE_FILE_MONITORING:
return
# Find new paths not yet being monitored # Find new paths not yet being monitored
new_paths = set() new_paths = set()
for path in config._path_mappings.keys(): for path in config._path_mappings.keys():
@@ -502,20 +515,28 @@ class CheckpointFileMonitor(BaseFileMonitor):
scanner = await CheckpointScanner.get_instance() scanner = await CheckpointScanner.get_instance()
monitor_paths = scanner.get_model_roots() monitor_paths = scanner.get_model_roots()
# Update monitor paths # Update monitor paths - but don't actually monitor them
for path in monitor_paths: for path in monitor_paths:
real_path = os.path.realpath(path).replace(os.sep, '/') real_path = os.path.realpath(path).replace(os.sep, '/')
cls._instance.monitor_paths.add(real_path) cls._instance.monitor_paths.add(real_path)
return cls._instance return cls._instance
async def initialize_paths(self): def start(self):
"""Initialize monitor paths from scanner""" """Override start to check global enable flag"""
if not self.monitor_paths: if not ENABLE_FILE_MONITORING:
scanner = await ServiceRegistry.get_checkpoint_scanner() logger.info("Checkpoint file monitoring is disabled via ENABLE_FILE_MONITORING setting")
monitor_paths = scanner.get_model_roots() return
# Update monitor paths logger.info("Checkpoint file monitoring is temporarily disabled")
for path in monitor_paths: # Skip the actual monitoring setup
real_path = os.path.realpath(path).replace(os.sep, '/') pass
self.monitor_paths.add(real_path)
async def initialize_paths(self):
"""Initialize monitor paths from scanner - currently disabled"""
if not ENABLE_FILE_MONITORING:
logger.info("Checkpoint path initialization skipped (monitoring disabled)")
return
logger.info("Checkpoint file path initialization skipped (monitoring disabled)")
pass

View File

@@ -11,6 +11,7 @@ dependencies = [
"beautifulsoup4", "beautifulsoup4",
"piexif", "piexif",
"Pillow", "Pillow",
"olefile", # for getting rid of warning message
"requests" "requests"
] ]

View File

@@ -5,4 +5,5 @@ watchdog
beautifulsoup4 beautifulsoup4
piexif piexif
Pillow Pillow
olefile
requests requests