refactor: Improve indexing notification handling and return values

- Enhanced error handling in the indexing process to differentiate between actual failures and cases where no new documents are processed.
- Updated notification messages to reflect the status accurately, including a message for when no new items are synced.
- Standardized return values across various indexer tasks to return `None` on success, simplifying logging and error management.
This commit is contained in:
Anish Sarkar 2026-01-14 13:16:11 +05:30
parent 18ec9543bd
commit 1ea0475f73
7 changed files with 34 additions and 18 deletions

View file

@ -1073,17 +1073,30 @@ async def _run_indexing_with_notifications(
error_message=None,
)
else:
# Failure or no documents processed
logger.error(
f"Indexing failed or no documents processed: {error_or_warning}"
)
if notification:
await NotificationService.connector_indexing.notify_indexing_completed(
session=session,
notification=notification,
indexed_count=0,
error_message=error_or_warning or "No documents processed",
)
# No new documents processed - check if this is an error or just no changes
if error_or_warning:
# Actual failure
logger.error(f"Indexing failed: {error_or_warning}")
if notification:
await NotificationService.connector_indexing.notify_indexing_completed(
session=session,
notification=notification,
indexed_count=0,
error_message=error_or_warning,
)
else:
# Success - just no new documents to index (all skipped/unchanged)
logger.info("Indexing completed: No new documents to process (all up to date)")
# Still update timestamp so ElectricSQL syncs and clears "Syncing" UI
if update_timestamp_func:
await update_timestamp_func(session, connector_id)
if notification:
await NotificationService.connector_indexing.notify_indexing_completed(
session=session,
notification=notification,
indexed_count=0,
error_message=None, # No error - sync succeeded
)
except Exception as e:
logger.error(f"Error in indexing task: {e!s}", exc_info=True)

View file

@ -358,8 +358,11 @@ class ConnectorIndexingNotificationHandler(BaseNotificationHandler):
status = "failed"
else:
title = f"Ready: {connector_name}"
item_text = "item" if indexed_count == 1 else "items"
message = f"Now searchable! {indexed_count} {item_text} synced."
if indexed_count == 0:
message = "Already up to date! No new items to sync."
else:
item_text = "item" if indexed_count == 1 else "items"
message = f"Now searchable! {indexed_count} {item_text} synced."
status = "completed"
metadata_updates = {

View file

@ -549,7 +549,7 @@ async def index_discord_messages(
logger.info(
f"Discord indexing completed: {documents_indexed} new messages, {documents_skipped} skipped"
)
return documents_indexed, result_message
return documents_indexed, None # Return None on success (result_message is for logging only)
except SQLAlchemyError as db_error:
await session.rollback()

View file

@ -464,7 +464,7 @@ async def index_notion_pages(
# Clean up the async client
await notion_client.close()
return total_processed, result_message
return total_processed, None # Return None on success (result_message is for logging only)
except SQLAlchemyError as db_error:
await session.rollback()

View file

@ -413,7 +413,7 @@ async def index_slack_messages(
logger.info(
f"Slack indexing completed: {documents_indexed} new channels, {documents_skipped} skipped"
)
return total_processed, result_message
return total_processed, None # Return None on success (result_message is for logging only)
except SQLAlchemyError as db_error:
await session.rollback()

View file

@ -460,7 +460,7 @@ async def index_teams_messages(
documents_indexed,
documents_skipped,
)
return total_processed, result_message
return total_processed, None # Return None on success (result_message is for logging only)
except SQLAlchemyError as db_error:
await session.rollback()

View file

@ -400,7 +400,7 @@ async def index_crawled_urls(
f"{documents_updated} updated, {documents_skipped} skipped, "
f"{len(failed_urls)} failed"
)
return total_processed, result_message
return total_processed, None # Return None on success (result_message is for logging only)
except SQLAlchemyError as db_error:
await session.rollback()