Skip to content

Commit cf1b107

Browse files
committed
Upgrade package to 0.2.7
1 parent 39fcf00 commit cf1b107

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ pydantic==1.10.4
33
python-ms-core==0.0.22
44
uvicorn==0.20.0
55
html_testRunner==1.2.1
6-
python-osw-validation==0.2.4
6+
python-osw-validation==0.2.7

src/osw_validator.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import uuid
1+
import gc
22
import logging
3-
import datetime
43
import urllib.parse
54
from typing import List
65
from python_ms_core import Core
@@ -89,6 +88,8 @@ def send_status(self, result: ValidationResult, upload_message: Upload):
8988
logger.info(f'Publishing message for : {upload_message.message_id}')
9089
except Exception as e:
9190
logger.error(f'Error occurred while publishing message for : {upload_message.message_id} with error: {e}')
91+
finally:
92+
gc.collect()
9293

9394

9495
def has_permission(self, roles: List[str], queue_message: Upload) -> bool:

src/validation.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import gc
12
import os
23
import shutil
34
import logging
@@ -47,7 +48,7 @@ def is_osw_valid(self, max_errors) -> ValidationResult:
4748
else:
4849
result.validation_message = 'Failed to validate because unknown file format'
4950
logger.error(f' Failed to validate because unknown file format')
50-
51+
gc.collect()
5152
return result
5253

5354
# Downloads the single file into a unique directory
@@ -56,15 +57,15 @@ def download_single_file(self, file_upload_path=None) -> str:
5657
unique_id = self.get_unique_id()
5758
if not is_exists:
5859
os.makedirs(DOWNLOAD_FILE_PATH)
59-
unique_directory = os.path.join(DOWNLOAD_FILE_PATH,unique_id)
60+
unique_directory = os.path.join(DOWNLOAD_FILE_PATH, unique_id)
6061
if not os.path.exists(unique_directory):
6162
os.makedirs(unique_directory)
62-
63+
6364
file = self.storage_client.get_file_from_url(self.container_name, file_upload_path)
6465
try:
6566
if file.file_path:
6667
file_path = os.path.basename(file.file_path)
67-
local_download_path = os.path.join(unique_directory,file_path)
68+
local_download_path = os.path.join(unique_directory, file_path)
6869
with open(local_download_path, 'wb') as blob:
6970
blob.write(file.get_stream())
7071
logger.info(f' File downloaded to location: {local_download_path}')
@@ -74,14 +75,14 @@ def download_single_file(self, file_upload_path=None) -> str:
7475
except Exception as e:
7576
traceback.print_exc()
7677
logger.error(e)
78+
finally:
79+
gc.collect()
7780

7881
# Generates a unique string for directory
7982
def get_unique_id(self) -> str:
8083
unique_id = uuid.uuid1().hex[0:24]
8184
return unique_id
8285

83-
84-
8586
@staticmethod
8687
def clean_up(path):
8788
if os.path.isfile(path):
@@ -91,3 +92,4 @@ def clean_up(path):
9192
# folder = os.path.join(DOWNLOAD_FILE_PATH, path)
9293
logger.info(f' Removing Folder: {path}')
9394
shutil.rmtree(path, ignore_errors=False)
95+
gc.collect()

0 commit comments

Comments
 (0)