mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-15 17:43:03 +03:00
fix: Add error handling for syncing in tasks.py (#2663)
This pull request adds error handling for the syncing process in the tasks.py file. Previously, if an error occurred during the syncing process, the program would crash. With this change, any exceptions that occur during syncing will be caught and logged, allowing the program to continue running. This improves the stability and reliability of the syncing functionality. Co-authored-by: Stan Girard <stan@quivr.app>
This commit is contained in:
parent
6f95a2d51c
commit
83f06dc5d2
@ -39,10 +39,20 @@ async def _process_sync_active():
|
||||
active = await sync_active_service.get_syncs_active_in_interval()
|
||||
|
||||
for sync in active:
|
||||
details_user_sync = sync_user_service.get_sync_user_by_id(sync.syncs_user_id)
|
||||
if details_user_sync["provider"].lower() == "google":
|
||||
await google_sync_utils.sync(sync_active_id=sync.id, user_id=sync.user_id)
|
||||
elif details_user_sync["provider"].lower() == "azure":
|
||||
await azure_sync_utils.sync(sync_active_id=sync.id, user_id=sync.user_id)
|
||||
else:
|
||||
logger.info("Provider not supported: %s", details_user_sync["provider"])
|
||||
try:
|
||||
details_user_sync = sync_user_service.get_sync_user_by_id(
|
||||
sync.syncs_user_id
|
||||
)
|
||||
if details_user_sync["provider"].lower() == "google":
|
||||
await google_sync_utils.sync(
|
||||
sync_active_id=sync.id, user_id=sync.user_id
|
||||
)
|
||||
elif details_user_sync["provider"].lower() == "azure":
|
||||
await azure_sync_utils.sync(
|
||||
sync_active_id=sync.id, user_id=sync.user_id
|
||||
)
|
||||
else:
|
||||
logger.info("Provider not supported: %s", details_user_sync["provider"])
|
||||
except Exception as e:
|
||||
logger.error(f"Error syncing: {e}")
|
||||
continue
|
||||
|
@ -5,7 +5,6 @@ from fastapi import UploadFile
|
||||
from google.auth.transport.requests import Request as GoogleRequest
|
||||
from google.oauth2.credentials import Credentials
|
||||
from googleapiclient.discovery import build
|
||||
from googleapiclient.errors import HttpError
|
||||
from logger import get_logger
|
||||
from modules.brain.repository.brains_vectors import BrainsVectors
|
||||
from modules.knowledge.repository.storage import Storage
|
||||
@ -125,9 +124,9 @@ class GoogleSyncUtils(BaseModel):
|
||||
# Check if the file already exists in the storage
|
||||
if check_file_exists(brain_id, file_name):
|
||||
logger.debug("🔥 File already exists in the storage: %s", file_name)
|
||||
|
||||
self.storage.remove_file(brain_id + "/" + file_name)
|
||||
BrainsVectors().delete_file_from_brain(brain_id, file_name)
|
||||
|
||||
|
||||
to_upload_file = UploadFile(
|
||||
file=BytesIO(file_data),
|
||||
@ -166,7 +165,7 @@ class GoogleSyncUtils(BaseModel):
|
||||
)
|
||||
|
||||
downloaded_files.append(file_name)
|
||||
except HttpError as error:
|
||||
except Exception as error:
|
||||
logger.error(
|
||||
"An error occurred while downloading Google Drive files: %s",
|
||||
error,
|
||||
|
Loading…
Reference in New Issue
Block a user