|
5 | 5 | from application.ports.queue import ITaskQueueService |
6 | 6 | from typing import Callable |
7 | 7 | import uuid |
8 | | -from domain.exceptions import ZipGenerationError, StorageDownloadError, InferenceError |
| 8 | +from domain.exceptions import ZipGenerationError, InferenceError |
9 | 9 | from application.dtos import ( |
10 | 10 | BackgroundEncodingResult, |
11 | 11 | BackgroundZipResult, |
@@ -45,20 +45,22 @@ async def execute( |
45 | 45 |
|
46 | 46 | valid_keys: list[str] = [] |
47 | 47 | valid_b64: list[str] = [] |
| 48 | + failed_keys: list[str] = [] |
48 | 49 | for key, b64 in zip(keys, b64_images): |
49 | 50 | if isinstance(b64, Exception): |
50 | | - raise StorageDownloadError( |
51 | | - f"Failed to download {key} after retries: {b64}" |
52 | | - ) |
| 51 | + logger.warning(f"Failed to download {key} after retries: {b64}. Skipping this image.") |
| 52 | + failed_keys.append(key) |
| 53 | + continue |
53 | 54 | elif b64 is not None: |
54 | 55 | valid_keys.append(key) |
55 | 56 | valid_b64.append(str(b64)) |
56 | 57 |
|
57 | 58 | if not valid_keys: |
58 | 59 | return { |
59 | 60 | "encoded": 0, |
60 | | - "no_encodings_found": len(keys), |
61 | | - "total": len(keys) |
| 61 | + "no_encodings_found": 0, |
| 62 | + "total": len(keys), |
| 63 | + "failures": failed_keys |
62 | 64 | } |
63 | 65 |
|
64 | 66 | try: |
@@ -94,11 +96,12 @@ async def execute( |
94 | 96 | logger.info(f"Database insert for {len(insert_data)} encodings took {db_time - db_start:.2f}s") |
95 | 97 |
|
96 | 98 | encoded = sum(1 for image_faces in results if any(f.get("embedding") for f in image_faces)) |
97 | | - no_encodings_found = len(keys) - encoded |
| 99 | + no_encodings_found = len(valid_keys) - encoded |
98 | 100 | return { |
99 | 101 | "encoded": encoded, |
100 | 102 | "no_encodings_found": no_encodings_found, |
101 | | - "total": len(keys) |
| 103 | + "total": len(keys), |
| 104 | + "failures": failed_keys |
102 | 105 | } |
103 | 106 | except Exception as e: |
104 | 107 | raise InferenceError(f"Failed to infer batch: {e}") from e |
|
0 commit comments