From 7a3ee26c8723d262fbfd00b8a7fd74d9ce4ec908 Mon Sep 17 00:00:00 2001 From: Krateng Date: Wed, 2 Dec 2020 20:09:19 +0100 Subject: [PATCH] Fixed wait page after database rebuild, closes GH-59 --- maloja/apis/native_v1.py | 4 +++- maloja/database.py | 10 ++++++++++ maloja/web/jinja/wait.jinja | 17 +++++++++-------- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/maloja/apis/native_v1.py b/maloja/apis/native_v1.py index f2796ae..35c7915 100644 --- a/maloja/apis/native_v1.py +++ b/maloja/apis/native_v1.py @@ -43,7 +43,8 @@ def server_info(): return { "name":settings.get_settings("NAME"), "version":version, - "versionstring":".".join(str(n) for n in version) + "versionstring":".".join(str(n) for n in version), + "db_status":dbstatus } @@ -257,6 +258,7 @@ def import_rulemodule(**keys): def rebuild(**keys): log("Database rebuild initiated!") sync() + dbstatus['rebuildinprogress'] = True from ..proccontrol.tasks.fixexisting import fix fix() global cla, coa diff --git a/maloja/database.py b/maloja/database.py index 25098ce..5d47604 100644 --- a/maloja/database.py +++ b/maloja/database.py @@ -44,6 +44,10 @@ import urllib dblock = Lock() #global database lock +dbstatus = { + "healthy":False, + "rebuildinprogress":False +} SCROBBLES = [] # Format: tuple(track_ref,timestamp,saved) ARTISTS = [] # Format: artist @@ -747,6 +751,9 @@ def start_db(): def build_db(): + global dbstatus + dbstatus['healthy'] = False + dbstatus['rebuildinprogress'] = True log("Building database...") @@ -810,6 +817,9 @@ def build_db(): global ISSUES ISSUES = check_issues() + dbstatus['healthy'] = True + dbstatus['rebuildinprogress'] = False + log("Database fully built!") diff --git a/maloja/web/jinja/wait.jinja b/maloja/web/jinja/wait.jinja index 952d0c2..a24006a 100644 --- a/maloja/web/jinja/wait.jinja +++ b/maloja/web/jinja/wait.jinja @@ -17,7 +17,8 @@ console.log("Probing..."); pending = true; var xhttp = new XMLHttpRequest(); - xhttp.open("GET","/apis/mlj_1/test", true); + xhttp.responseType = 'json'; + xhttp.open("GET","/apis/mlj_1/serverinfo", true); xhttp.onreadystatechange = goback; xhttp.send(); @@ -26,15 +27,15 @@ } function goback() { - if ((this.readyState == 4) && (this.status == 205)) { - console.log("Not ready yet!"); + if ((this.readyState == 4) && (this.status == 200)) { + var response = this.response; + var status = response['db_status']; + console.log(response); + if (status['healthy'] && !status['rebuildinprogress']) { + window.location = "/issues"; + } pending = false; } - if ((this.readyState == 4) && (this.status == 204)) { - console.log("K"); - pending = false; - window.location = "/issues"; - } }