Update connector.py

This commit is contained in:
Edwin Jose 2025-09-10 12:40:58 -04:00
parent 3f198c4993
commit 67063441f5

View file

@ -82,7 +82,8 @@ class GoogleDriveConnector(BaseConnector):
_FOLDER_ID_ALIASES = ("folder_ids", "selected_folder_ids", "selected_folders") _FOLDER_ID_ALIASES = ("folder_ids", "selected_folder_ids", "selected_folders")
def log(self, message: str) -> None: def log(self, message: str) -> None:
print(message) #NOTE: TBD Remove
logger.debug(message) # TBD Remove
def emit(self, doc: ConnectorDocument) -> None: def emit(self, doc: ConnectorDocument) -> None:
""" """
@ -91,7 +92,7 @@ class GoogleDriveConnector(BaseConnector):
""" """
# If BaseConnector has an emit method, call super().emit(doc) # If BaseConnector has an emit method, call super().emit(doc)
# Otherwise, implement your custom logic here. # Otherwise, implement your custom logic here.
print(f"Emitting document: {doc.id} ({doc.filename})") logger.debug(f"Emitting document: {doc.id} ({doc.filename})")
def __init__(self, config: Dict[str, Any]) -> None: def __init__(self, config: Dict[str, Any]) -> None:
# Read from config OR env (backend env, not NEXT_PUBLIC_*): # Read from config OR env (backend env, not NEXT_PUBLIC_*):
@ -433,7 +434,7 @@ class GoogleDriveConnector(BaseConnector):
# If still not authenticated, bail (caller should kick off OAuth init) # If still not authenticated, bail (caller should kick off OAuth init)
if not await self.oauth.is_authenticated(): if not await self.oauth.is_authenticated():
self.log("authenticate: no valid credentials; run OAuth init/callback first.") logger.debug("authenticate: no valid credentials; run OAuth init/callback first.")
return False return False
# Build Drive service from OAuth helper # Build Drive service from OAuth helper
@ -482,7 +483,7 @@ class GoogleDriveConnector(BaseConnector):
except Exception as e: except Exception as e:
# Optionally log error with your base class logger # Optionally log error with your base class logger
try: try:
self.log(f"GoogleDriveConnector.list_files failed: {e}") logger.error(f"GoogleDriveConnector.list_files failed: {e}")
except Exception: except Exception:
pass pass
return {"files": [], "next_page_token": None} return {"files": [], "next_page_token": None}
@ -500,7 +501,8 @@ class GoogleDriveConnector(BaseConnector):
except Exception as e: except Exception as e:
# Use your base class logger if available # Use your base class logger if available
try: try:
self.log(f"Download failed for {file_id}: {e}") #NOTE: TBD Remove the try catch
logger.error(f"Download failed for {file_id}: {e}")
except Exception: except Exception:
pass pass
raise raise
@ -567,7 +569,7 @@ class GoogleDriveConnector(BaseConnector):
except Exception as e: except Exception as e:
# Optional: use your base logger # Optional: use your base logger
try: try:
self.log(f"Failed to get start page token: {e}") logger.error(f"Failed to get start page token: {e}")
except Exception: except Exception:
pass pass
raise raise
@ -634,7 +636,7 @@ class GoogleDriveConnector(BaseConnector):
ok = await self.authenticate() ok = await self.authenticate()
if not ok: if not ok:
try: try:
self.log("cleanup_subscription: not authenticated") logger.error("cleanup_subscription: not authenticated")
except Exception: except Exception:
pass pass
return False return False
@ -662,7 +664,7 @@ class GoogleDriveConnector(BaseConnector):
if not resource_id: if not resource_id:
try: try:
self.log( logger.error(
f"cleanup_subscription: missing resource_id for channel {subscription_id}. " f"cleanup_subscription: missing resource_id for channel {subscription_id}. "
f"Persist (channel_id, resource_id) when creating the subscription." f"Persist (channel_id, resource_id) when creating the subscription."
) )
@ -684,7 +686,7 @@ class GoogleDriveConnector(BaseConnector):
except Exception as e: except Exception as e:
try: try:
self.log(f"cleanup_subscription failed for {subscription_id}: {e}") logger.error(f"cleanup_subscription failed for {subscription_id}: {e}")
except Exception: except Exception:
pass pass
return False return False
@ -708,7 +710,7 @@ class GoogleDriveConnector(BaseConnector):
ok = await self.authenticate() ok = await self.authenticate()
if not ok: if not ok:
try: try:
self.log("handle_webhook: not authenticated") logger.error("handle_webhook: not authenticated")
except Exception: except Exception:
pass pass
return affected return affected
@ -728,7 +730,7 @@ class GoogleDriveConnector(BaseConnector):
except Exception as e: except Exception as e:
selected_ids = set() selected_ids = set()
try: try:
self.log(f"handle_webhook: scope build failed, proceeding unfiltered: {e}") logger.error(f"handle_webhook: scope build failed, proceeding unfiltered: {e}")
except Exception: except Exception:
pass pass
@ -797,7 +799,7 @@ class GoogleDriveConnector(BaseConnector):
except Exception as e: except Exception as e:
try: try:
self.log(f"handle_webhook failed: {e}") logger.error(f"handle_webhook failed: {e}")
except Exception: except Exception:
pass pass
return [] return []
@ -814,7 +816,7 @@ class GoogleDriveConnector(BaseConnector):
blob = self._download_file_bytes(meta) blob = self._download_file_bytes(meta)
except HttpError as e: except HttpError as e:
# Skip/record failures # Skip/record failures
self.log(f"Failed to download {meta.get('name')} ({meta.get('id')}): {e}") logger.error(f"Failed to download {meta.get('name')} ({meta.get('id')}): {e}")
continue continue
from datetime import datetime from datetime import datetime