add: fastapi wrapped baru mau di tes di Gajah Mada
This commit is contained in:
@@ -42,6 +42,36 @@ def cleanup_dicom_files():
|
||||
# Clear the registry after cleanup
|
||||
_cleanup_dirs.clear()
|
||||
|
||||
def cleanup_study_directory(study_uid):
|
||||
"""
|
||||
Immediately remove the directory for a specific study.
|
||||
|
||||
Args:
|
||||
study_uid (str): Study Instance UID of the study to clean up
|
||||
|
||||
Returns:
|
||||
bool: True if cleanup was successful, False otherwise
|
||||
"""
|
||||
study_dir = os.path.join(settings.DICOM_STORE_DIR, study_uid)
|
||||
|
||||
if not os.path.exists(study_dir):
|
||||
logger.debug(f"Cleanup: Study directory does not exist: {study_dir}")
|
||||
return True
|
||||
|
||||
try:
|
||||
shutil.rmtree(study_dir)
|
||||
logger.info(f"Cleanup: Removed DICOM files from {study_dir}")
|
||||
|
||||
# Also remove from the registry if it's there
|
||||
global _cleanup_dirs
|
||||
if study_dir in _cleanup_dirs:
|
||||
_cleanup_dirs.remove(study_dir)
|
||||
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"Cleanup: Failed to remove DICOM files from {study_dir}: {str(e)}")
|
||||
return False
|
||||
|
||||
def register_exit_handlers():
|
||||
"""
|
||||
Register cleanup handlers for various exit scenarios.
|
||||
|
||||
Reference in New Issue
Block a user