To complete my expertise in data storage, I joined the editor Oracle, before joining InterSystems in 2001.
My skills in data processing have therefore been extended, from multi-model storage, interoperability (and more particularly on health exchange standards), to real-time analysis and artificial intelligence (AI / ML), so as to cover a broad spectrum of the data lifecycle in all industries.
Pour compléter mon expertise en stockage de données, j'ai ensuite intégré l'éditeur Oracle, avant de rejoindre InterSystems France dès 2001.
Mes compétences en traitement de la donnée se sont dès lors étendues, depuis le stockage multi-modèles, l'interopérabilité (et plus particulièrement sur les standards d'échanges en santé), jusqu'à l'analyse en temps-réel et à l'intelligence artificielle (IA/ML), de manière à couvrir un large spectre du cycle de vie de la donnée.
You can schedule the following task which removes any file from a directory, based on its age, using Python:
Class admin.purge Extends %SYS.Task.Definition
{
Property Directory As %String(MAXLEN = 2000) [ InitialExpression = "/usr/irissys/mgr/Backup" ];
Property DaysToKeep As %Integer(VALUELIST = ",0,1,2,3,4,5") [ InitialExpression = "1" ];
Method OnTask() As %Status
{
set sc = $$$OK
Try {
do ..purge(..Directory,..DaysToKeep)
}
Catch ex {
Set sc=ex.AsStatus()
}
return sc
}
ClassMethod purge(path As %String, daysToKeep As %Integer) As %Status [ Language = python ]
{
import iris
import os
import time
from datetime import datetime, timedelta
event = "[TASK PURGE OLD BACKUP FILES]"
class FileDeletionError(Exception):
"""Custom exception for file deletion errors."""
pass
def delete_old_files(path, days_limit):
limit_date = datetime.now() - timedelta(days=int(days_limit))
for file in os.listdir(path):
file_path = os.path.join(path, file)
if os.path.isfile(file_path):
creation_date = datetime.fromtimestamp(os.path.getctime(file_path))
if creation_date < limit_date:
try:
os.remove(file_path)
iris.cls("%SYS.System").WriteToConsoleLog(f"{event} Deleted: {str(file_path)}")
except PermissionError:
raise FileDeletionError(f"Permission error: Unable to delete {file}")
except FileNotFoundError:
raise FileDeletionError(f"File not found: {file}")
except Exception as e:
raise FileDeletionError(f"Unexpected error while deleting {file}: {str(e)}")
try:
iris.cls("%SYS.System").WriteToConsoleLog(f"{event} Executing task to delete backup files from directory {path} created more than {str(daysToKeep)} days ago")
days_limit = daysToKeep
delete_old_files(path, days_limit)
except FileDeletionError as e:
iris.cls("%SYS.System").WriteToConsoleLog(f"{event} Error during deletion: {str(e)}",0,1)
except Exception as e:
iris.cls("%SYS.System").WriteToConsoleLog(f"{event} Unexpected error: {str(e)}",0,1)
}
}
The task logs its actions in messages.log :
01/13/25-18:21:00:549 (35722) 0 [Utility.Event] [TASK PURGE OLD BACKUP FILES] Executing task to delete backup files from directory /usr/irissys/mgr/Backup created more than 0 days ago
01/13/25-18:21:00:550 (35722) 0 [Utility.Event] [TASK PURGE OLD BACKUP FILES] Deleted: /usr/irissys/mgr/Backup/FullAllDatabases_20250113_009.cbk
01/13/25-18:21:00:550 (35722) 0 [Utility.Event] [TASK PURGE OLD BACKUP FILES] Deleted: /usr/irissys/mgr/Backup/FullAllDatabases_20250113_008.log
01/13/25-18:21:00:598 (35722) 0 [Utility.Event] [TASK PURGE OLD BACKUP FILES] Deleted: /usr/irissys/mgr/Backup/FullAllDatabases_20250113_008.cbk
01/13/25-18:21:00:598 (35722) 0 [Utility.Event] [TASK PURGE OLD BACKUP FILES] Deleted: /usr/irissys/mgr/Backup/FullAllDatabases_20250113_009.log
Congrats to all 😀
You can schedule the following task which removes any file from a directory, based on its age, using Python:
Class admin.purge Extends %SYS.Task.Definition { Property Directory As %String(MAXLEN = 2000) [ InitialExpression = "/usr/irissys/mgr/Backup" ]; Property DaysToKeep As %Integer(VALUELIST = ",0,1,2,3,4,5") [ InitialExpression = "1" ]; Method OnTask() As %Status { set sc = $$$OK Try { do ..purge(..Directory,..DaysToKeep) } Catch ex { Set sc=ex.AsStatus() } return sc } ClassMethod purge(path As %String, daysToKeep As %Integer) As %Status [ Language = python ] { import iris import os import time from datetime import datetime, timedelta event = "[TASK PURGE OLD BACKUP FILES]" class FileDeletionError(Exception): """Custom exception for file deletion errors.""" pass def delete_old_files(path, days_limit): limit_date = datetime.now() - timedelta(days=int(days_limit)) for file in os.listdir(path): file_path = os.path.join(path, file) if os.path.isfile(file_path): creation_date = datetime.fromtimestamp(os.path.getctime(file_path)) if creation_date < limit_date: try: os.remove(file_path) iris.cls("%SYS.System").WriteToConsoleLog(f"{event} Deleted: {str(file_path)}") except PermissionError: raise FileDeletionError(f"Permission error: Unable to delete {file}") except FileNotFoundError: raise FileDeletionError(f"File not found: {file}") except Exception as e: raise FileDeletionError(f"Unexpected error while deleting {file}: {str(e)}") try: iris.cls("%SYS.System").WriteToConsoleLog(f"{event} Executing task to delete backup files from directory {path} created more than {str(daysToKeep)} days ago") days_limit = daysToKeep delete_old_files(path, days_limit) except FileDeletionError as e: iris.cls("%SYS.System").WriteToConsoleLog(f"{event} Error during deletion: {str(e)}",0,1) except Exception as e: iris.cls("%SYS.System").WriteToConsoleLog(f"{event} Unexpected error: {str(e)}",0,1) } }
01/13/25-18:21:00:549 (35722) 0 [Utility.Event] [TASK PURGE OLD BACKUP FILES] Executing task to delete backup files from directory /usr/irissys/mgr/Backup created more than 0 days ago 01/13/25-18:21:00:550 (35722) 0 [Utility.Event] [TASK PURGE OLD BACKUP FILES] Deleted: /usr/irissys/mgr/Backup/FullAllDatabases_20250113_009.cbk 01/13/25-18:21:00:550 (35722) 0 [Utility.Event] [TASK PURGE OLD BACKUP FILES] Deleted: /usr/irissys/mgr/Backup/FullAllDatabases_20250113_008.log 01/13/25-18:21:00:598 (35722) 0 [Utility.Event] [TASK PURGE OLD BACKUP FILES] Deleted: /usr/irissys/mgr/Backup/FullAllDatabases_20250113_008.cbk 01/13/25-18:21:00:598 (35722) 0 [Utility.Event] [TASK PURGE OLD BACKUP FILES] Deleted: /usr/irissys/mgr/Backup/FullAllDatabases_20250113_009.log