add force option to movie reload

In case an import fails we need to skip checking whether the IMDb
export dumps changed.
This commit is contained in:
ducklet 2021-08-06 14:23:21 +02:00
parent b2caaa8bc3
commit 181719c6d9
2 changed files with 6 additions and 3 deletions

View file

@ -237,7 +237,7 @@ async def import_from_file(*, basics_path: Path, ratings_path: Path):
await db.set_import_progress(100)
async def load_from_web():
async def load_from_web(*, force: bool = False):
"""Refresh the full IMDb movie database.
The latest dumps are first downloaded and then imported into the database.
@ -267,7 +267,7 @@ async def load_from_web():
or bastics_mtime != basics_file.stat().st_mtime
)
if is_changed:
if force or is_changed:
await import_from_file(basics_path=basics_file, ratings_path=ratings_file)
except BaseException as err:

View file

@ -358,6 +358,9 @@ _import_lock = asyncio.Lock()
@requires(["authenticated", "admin"])
async def load_imdb_movies(request):
params = request.query_params
force = truthy(params.get("force"))
async with _import_lock:
progress = await db.get_import_progress()
if progress and not progress.stopped:
@ -368,7 +371,7 @@ async def load_imdb_movies(request):
await db.set_import_progress(0)
task = BackgroundTask(imdb_import.load_from_web)
task = BackgroundTask(imdb_import.load_from_web, force=force)
return JSONResponse(
{"status": "Import started.", "progress": 0.0}, background=task, status_code=202
)