Skip to content

Commit

Permalink
Try track successful uploaded images
Browse files Browse the repository at this point in the history
  • Loading branch information
Audionut committed Sep 29, 2024
1 parent 2a41189 commit 336ee62
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -2529,6 +2529,7 @@ def upload_screens(self, meta, screens, img_host_num, i, total_screens, custom_i
img_host = meta['imghost'] # Use the correctly updated image host from meta

image_list = []
successfully_uploaded = set() # Keep track of uploaded images across hosts

if custom_img_list:
image_glob = custom_img_list
Expand Down Expand Up @@ -2563,9 +2564,10 @@ def upload_screens(self, meta, screens, img_host_num, i, total_screens, custom_i
TimeRemainingColumn()
) as progress:
while True:
upload_task = progress.add_task(f"[green]Uploading Screens to {img_host}...", total=len(image_glob[-screens:]))

for image in image_glob[-screens:]:
remaining_images = [img for img in image_glob[-screens:] if img not in successfully_uploaded]
upload_task = progress.add_task(f"[green]Uploading Screens to {img_host}...", total=len(remaining_images))

for image in remaining_images:
retry_count = 0
while retry_count < max_retries:
try:
Expand Down Expand Up @@ -2654,6 +2656,7 @@ def upload_screens(self, meta, screens, img_host_num, i, total_screens, custom_i
# Add the image details to the list
image_dict = {'img_url': img_url, 'raw_url': raw_url, 'web_url': web_url}
image_list.append(image_dict)
successfully_uploaded.add(image) # Track successfully uploaded images
progress.advance(upload_task)
i += 1
break # Break the retry loop if successful
Expand All @@ -2672,7 +2675,7 @@ def upload_screens(self, meta, screens, img_host_num, i, total_screens, custom_i
console.print(f"\n[cyan]Completed uploading images. Total uploaded: {len(image_list)}")
return image_list, i

# If we broke out of the loop due to a failure, switch to the next host and retry
# If we broke out of the loop due to a failure, switch to the next host and retry only remaining images
img_host_num += 1
img_host = self.config['DEFAULT'].get(f'img_host_{img_host_num}')
if not img_host:
Expand Down

0 comments on commit 336ee62

Please sign in to comment.