Skip to content

Commit 85a6735

Browse files
committed
Re-index after migration, fixed using temp files
Using app.ctx doesn't work anymore, as any other memory-variant I tried.
1 parent 6ecd18c commit 85a6735

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

  • bases/renku_data_services/data_api

bases/renku_data_services/data_api/main.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import argparse
44
import asyncio
55
import os
6+
import pathlib
7+
import tempfile
68
from os import environ
79
from 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

Comments
 (0)