From 181719c6d98f89c38c79d319a087c3265f8dd326 Mon Sep 17 00:00:00 2001 From: ducklet Date: Fri, 6 Aug 2021 14:23:21 +0200 Subject: [PATCH] add force option to movie reload In case an import fails we need to skip checking whether the IMDb export dumps changed. --- unwind/imdb_import.py | 4 ++-- unwind/web.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/unwind/imdb_import.py b/unwind/imdb_import.py index e29a981..0292716 100644 --- a/unwind/imdb_import.py +++ b/unwind/imdb_import.py @@ -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: diff --git a/unwind/web.py b/unwind/web.py index b8306ef..efbbb13 100644 --- a/unwind/web.py +++ b/unwind/web.py @@ -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 )