Browse Source

[mob][photos] Retries for fetching face embeddings

laurenspriem 1 year ago
parent
commit
3b8cae068e
1 changed files with 13 additions and 2 deletions
  1. 13 2
      mobile/lib/services/machine_learning/face_ml/face_ml_service.dart

+ 13 - 2
mobile/lib/services/machine_learning/face_ml/face_ml_service.dart

@@ -484,7 +484,7 @@ class FaceMlService {
   /// Analyzes all the images in the database with the latest ml version and stores the results in the database.
   /// Analyzes all the images in the database with the latest ml version and stores the results in the database.
   ///
   ///
   /// This function first checks if the image has already been analyzed with the lastest faceMlVersion and stored in the database. If so, it skips the image.
   /// This function first checks if the image has already been analyzed with the lastest faceMlVersion and stored in the database. If so, it skips the image.
-  Future<void> indexAllImages() async {
+  Future<void> indexAllImages({int retryFetchCount = 10}) async {
     if (isImageIndexRunning) {
     if (isImageIndexRunning) {
       _logger.warning("indexAllImages is already running, skipping");
       _logger.warning("indexAllImages is already running, skipping");
       return;
       return;
@@ -589,7 +589,18 @@ class FaceMlService {
                 .info('already indexed files ${remoteFileIdToVersion.length}');
                 .info('already indexed files ${remoteFileIdToVersion.length}');
           } catch (e, s) {
           } catch (e, s) {
             _logger.severe("err while getting files embeddings", e, s);
             _logger.severe("err while getting files embeddings", e, s);
-            rethrow;
+            if (retryFetchCount < 1000) {
+              Future.delayed(Duration(seconds: retryFetchCount), () {
+                unawaited(indexAllImages(retryFetchCount: retryFetchCount * 2));
+              });
+              return;
+            } else {
+              _logger.severe(
+                  "Failed to fetch embeddings for files after multiple retries",
+                  e,
+                  s,);
+              rethrow;
+            }
           }
           }
         }
         }
         final smallerChunks = chunk.chunks(_parallelism);
         final smallerChunks = chunk.chunks(_parallelism);