Skip to content

Commit

Permalink
Merge pull request #24 from PEM-Humboldt/removeFileOnFailure
Browse files Browse the repository at this point in the history
adjust method upload collection
  • Loading branch information
denarch22 authored Jan 14, 2025
2 parents f23f081 + 7d49300 commit 765ff80
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class Collection:

def __init__(self):
self.uploaded_urls = []
self.items = []
self.dates = []
self.longs = []
Expand Down Expand Up @@ -202,7 +203,17 @@ def upload_collection(self):

except Exception as e:
logger.error(f"Error uploading collection: {e}")
raise RuntimeError(f"Error uploading collection: {e}")

for url in self.uploaded_urls:
try:
self.storage.remove_file(url)
logger.info(f"Removed uploaded file: {url}")
except Exception as cleanup_error:
logger.error(
f"Error cleaning up uploaded file {url}: {cleanup_error}"
)

raise RuntimeError(f"Failed to upload collection: {e}")

def convert_layers(self, input_dir, output_dir):
"""
Expand All @@ -221,6 +232,7 @@ def upload_layers(self, output_folder):
"""
Upload item layers to storage.
"""
self.uploaded_urls = []
if self.items:
for i, item in enumerate(self.items):
logger.info(f"Uploading {item['input_file']}")
Expand All @@ -233,6 +245,7 @@ def upload_layers(self, output_folder):
)

if final_url:
self.uploaded_urls.append(final_url)
remove(file_path)

self.stac_items[i].add_asset(
Expand Down

0 comments on commit 765ff80

Please sign in to comment.