33import argparse
44import asyncio
55import os
6+ import pathlib
7+ import tempfile
68from os import environ
79from typing import TYPE_CHECKING , Any
810
@@ -165,8 +167,10 @@ async def do_solr_migrations(app: Sanic) -> None:
165167 await migrator .ensure_core ()
166168 result = await migrator .migrate (entity_schema .all_migrations )
167169 # starting background tasks can only be done in `main_process_ready`
168- app .ctx .solr_reindex = result .requires_reindex
169170 logger .info (f"SOLR migration done: { result } " )
171+ if result .requires_reindex :
172+ file = tempfile .gettempdir () + "/solr_reindex"
173+ pathlib .Path (file ).touch ()
170174
171175 @app .before_server_start
172176 async def setup_rclone_validator (app : Sanic ) -> None :
@@ -176,8 +180,10 @@ async def setup_rclone_validator(app: Sanic) -> None:
176180 @app .after_server_start
177181 async def ready (app : Sanic ) -> None :
178182 """Application ready event handler."""
179- logger .info (f">>>>>> SHOULD RUN RE-INDEX NOW. { getattr (app .ctx , "solr_reindex" , False )} " )
180- if getattr (app .ctx , "solr_reindex" , False ):
183+ file = tempfile .gettempdir () + "/solr_reindex"
184+ do_reindex = pathlib .Path (file ).exists ()
185+ if do_reindex :
186+ pathlib .Path (file ).unlink ()
181187 logger .info ("Creating solr reindex task, as required by migrations." )
182188 app .add_task (solr_reindex (dependency_manager .search_reprovisioning ))
183189
0 commit comments