From ea928f3532bfc06c5045f841b5958105b5e55eb5 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 3 Nov 2025 19:05:34 +0100 Subject: [PATCH] codice x detele_after_processing --- vm1/src/utils/config/loader_ftp_csv.py | 4 ++++ vm1/src/utils/connect/file_management.py | 8 ++++++++ vm2/src/utils/config/loader_ftp_csv.py | 4 ++++ vm2/src/utils/connect/file_management.py | 8 ++++++++ 4 files changed, 24 insertions(+) diff --git a/vm1/src/utils/config/loader_ftp_csv.py b/vm1/src/utils/config/loader_ftp_csv.py index a6e1bf7..defa2f1 100644 --- a/vm1/src/utils/config/loader_ftp_csv.py +++ b/vm1/src/utils/config/loader_ftp_csv.py @@ -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") diff --git a/vm1/src/utils/connect/file_management.py b/vm1/src/utils/connect/file_management.py index 62aa3ba..4f724f0 100644 --- a/vm1/src/utils/connect/file_management.py +++ b/vm1/src/utils/connect/file_management.py @@ -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}") diff --git a/vm2/src/utils/config/loader_ftp_csv.py b/vm2/src/utils/config/loader_ftp_csv.py index a6e1bf7..defa2f1 100644 --- a/vm2/src/utils/config/loader_ftp_csv.py +++ b/vm2/src/utils/config/loader_ftp_csv.py @@ -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") diff --git a/vm2/src/utils/connect/file_management.py b/vm2/src/utils/connect/file_management.py index 62aa3ba..4f724f0 100644 --- a/vm2/src/utils/connect/file_management.py +++ b/vm2/src/utils/connect/file_management.py @@ -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}")