@@ -148,7 +148,6 @@ async def get_discord_settings(
148148)
149149async 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)
367366async 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