codice x detele_after_processing

This commit is contained in:
2025-11-03 19:05:34 +01:00
parent 93584252ec
commit ea928f3532
4 changed files with 24 additions and 0 deletions

View File

@@ -34,6 +34,10 @@ class Config:
self.fileext = c.get("ftpserver", "fileext").upper().split("|")
self.defperm = c.get("ftpserver", "defaultUserPerm")
# File processing behavior: delete files after successful processing
# Set DELETE_AFTER_PROCESSING=true in docker-compose to enable
self.delete_after_processing = os.getenv("DELETE_AFTER_PROCESSING", "false").lower() in ("true", "1", "yes")
# CSV FILE setting
self.csvfs = c.get("csvfs", "path")

View File

@@ -109,6 +109,14 @@ async def on_file_received_async(self: object, file: str) -> None:
# Note: autocommit=True in connection, no need for explicit commit
logger.info(f"File {new_filename} loaded successfully")
# Delete file after successful processing if configured
if getattr(cfg, 'delete_after_processing', False):
try:
os.remove(f"{path}/{new_filename}")
logger.info(f"File {new_filename} deleted after successful processing")
except Exception as e:
logger.warning(f"Failed to delete file {new_filename}: {e}")
except Exception as e:
logger.error(f"File {new_filename} not loaded. Held in user path.")
logger.error(f"{e}")

View File

@@ -34,6 +34,10 @@ class Config:
self.fileext = c.get("ftpserver", "fileext").upper().split("|")
self.defperm = c.get("ftpserver", "defaultUserPerm")
# File processing behavior: delete files after successful processing
# Set DELETE_AFTER_PROCESSING=true in docker-compose to enable
self.delete_after_processing = os.getenv("DELETE_AFTER_PROCESSING", "false").lower() in ("true", "1", "yes")
# CSV FILE setting
self.csvfs = c.get("csvfs", "path")

View File

@@ -109,6 +109,14 @@ async def on_file_received_async(self: object, file: str) -> None:
# Note: autocommit=True in connection, no need for explicit commit
logger.info(f"File {new_filename} loaded successfully")
# Delete file after successful processing if configured
if getattr(cfg, 'delete_after_processing', False):
try:
os.remove(f"{path}/{new_filename}")
logger.info(f"File {new_filename} deleted after successful processing")
except Exception as e:
logger.warning(f"Failed to delete file {new_filename}: {e}")
except Exception as e:
logger.error(f"File {new_filename} not loaded. Held in user path.")
logger.error(f"{e}")