Skip to content

Commit e6f75ce

Browse files
authored
fix: revalidate domain in reindexing callback after first reindex (Ask AI enabled) (#5871)
1 parent 449a5f0 commit e6f75ce

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

servers/fai/src/fai/routes/settings.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ async def get_discord_settings(
148148
)
149149
async def enable_ask_ai(
150150
request: EnableAskAiRequest,
151-
background_tasks: BackgroundTasks,
152151
db: AsyncSession = Depends(get_db),
153152
) -> EnableAskAiResponse:
154153
"""Enable Ask AI for multiple domains with specified locations and trigger reindex.
@@ -366,7 +365,6 @@ async def reindex_ask_ai(
366365
)
367366
async def get_toggle_status(
368367
domain: str,
369-
background_tasks: BackgroundTasks,
370368
db: AsyncSession = Depends(get_db),
371369
_: None = Depends(verify_token),
372370
) -> ToggleStatusResponse:
@@ -471,7 +469,9 @@ async def set_job_id(
471469
"/settings/ask-ai/reindex-callback",
472470
openapi_extra={"x-fern-audiences": ["internal"]},
473471
)
474-
async def reindex_callback(request: ReindexCallbackRequest, db: AsyncSession = Depends(get_db)) -> JSONResponse:
472+
async def reindex_callback(
473+
request: ReindexCallbackRequest, background_tasks: BackgroundTasks, db: AsyncSession = Depends(get_db)
474+
) -> JSONResponse:
475475
"""Handle callback from SQS reindexing worker when reindex completes."""
476476
try:
477477
LOGGER.info(f"Received reindex callback - status: {request.status}, messageId: {request.sourceMessageId}")
@@ -487,8 +487,12 @@ async def reindex_callback(request: ReindexCallbackRequest, db: AsyncSession = D
487487

488488
if request.status == "success":
489489
LOGGER.info(f"Reindex completed successfully for domain {existing_record.domain}")
490+
was_first_reindex = existing_record.last_reindex_time is None
490491
existing_record.job_id = None
491492
existing_record.last_reindex_time = datetime.utcnow()
493+
494+
if was_first_reindex:
495+
background_tasks.add_task(revalidate_domain, existing_record.domain)
492496
else:
493497
LOGGER.error(f"Reindex failed for domain {existing_record.domain}")
494498
existing_record.job_id = None

0 commit comments

Comments
 (0)