fix monitoring for add_ files

This commit is contained in:
m0duspwnens
2025-01-28 11:22:26 -05:00
parent b66aafd168
commit e32dbad0d0

View File

@@ -580,26 +580,6 @@ def process_add_file(file_path: str, base_path: str) -> None:
log.error("Failed to process add file %s: %s", file_path, str(e)) log.error("Failed to process add file %s: %s", file_path, str(e))
raise raise
def monitor_add_files(base_path: str) -> None:
"""
Monitor directories for add_* files and process them.
Args:
base_path: Base path to monitor for add_* files
"""
pattern = os.path.join(base_path, '*', 'add_*')
try:
for file_path in glob.glob(pattern):
log.info("Found new VM request file: %s", file_path)
try:
process_add_file(file_path, base_path)
except Exception as e:
log.error("Failed to process file %s: %s", file_path, str(e))
except Exception as e:
log.error("Error monitoring add files: %s", str(e))
raise
def start(interval: int = DEFAULT_INTERVAL, def start(interval: int = DEFAULT_INTERVAL,
base_path: str = DEFAULT_BASE_PATH) -> None: base_path: str = DEFAULT_BASE_PATH) -> None:
""" """
@@ -614,18 +594,25 @@ def start(interval: int = DEFAULT_INTERVAL,
if not validate_hvn_license(): if not validate_hvn_license():
return return
processed_files = set()
while True: while True:
try: try:
for file_path in glob.glob(os.path.join(base_path, '*', 'add_*')): pattern = os.path.join(base_path, '*', 'add_*')
if file_path not in processed_files: log.debug("Scanning for VM request files with pattern: %s", pattern)
try:
files = glob.glob(pattern)
if files:
log.debug("Found %d VM request file(s): %s", len(files), files)
for file_path in files:
log.info("Processing VM request file: %s", file_path)
try: try:
process_add_file(file_path, base_path) process_add_file(file_path, base_path)
processed_files.add(file_path)
except Exception as e: except Exception as e:
log.error("Failed to process file %s: %s", file_path, str(e)) log.error("Failed to process file %s: %s", file_path, str(e))
# Still mark as processed to avoid retrying except Exception as e:
processed_files.add(file_path) log.error("Error scanning for VM request files: %s", str(e))
except Exception as e: except Exception as e:
log.error("Error in main engine loop: %s", str(e)) log.error("Error in main engine loop: %s", str(e))