From aaabcafcfef92a43a9099dcd2f592f85eeb5283c Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Sun, 11 Aug 2024 15:43:41 +0300 Subject: [PATCH] Message while database reset ongoing.. untested --- core/utils.py | 7 +++++++ core/views/scans.py | 11 +++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/core/utils.py b/core/utils.py index 39233d3..f49ef26 100644 --- a/core/utils.py +++ b/core/utils.py @@ -47,7 +47,14 @@ sha = hashlib.new('sha256') throw = 35.0 +class DatabaseResetOngoing(Exception): + """Exception class for errors while the server is reimporting everything""" + def __init__(self, message): + self.message = message + + def __str__(self): + return f"DatabaseResetOngoing: {self.message}" # This is module-level executable. This is a Bad Thing. Especially when it touches the file system. try: diff --git a/core/views/scans.py b/core/views/scans.py index f24b972..1d86d18 100644 --- a/core/views/scans.py +++ b/core/views/scans.py @@ -6,6 +6,7 @@ from django.conf import settings from django.http import HttpResponse from django.shortcuts import render + from troggle.core.models.caves import GetCaveLookup from troggle.core.models.survex import SingleScan, SurvexBlock, SurvexPersonRole from troggle.core.models.wallets import Wallet @@ -14,7 +15,7 @@ from troggle.core.views.expo import getmimetype from troggle.parsers.caves import add_cave_to_pending_list from troggle.parsers.people import GetPersonExpeditionNameLookup from troggle.parsers.survex import set_walletdate -from troggle.core.utils import current_expo +from troggle.core.utils import current_expo, DatabaseResetOngoing """ @@ -277,7 +278,13 @@ def walletslistyear(request, year): def ticksyearwallet(year): manywallets = [] - manywallets = Wallet.objects.filter(walletyear__year=year) + try: + manywallets = Wallet.objects.filter(walletyear__year=year) + except OperationalError: + # Reset is ongoing on server + raise DatabaseResetOngoing( + f"Expo Database re-import ongoing on server.\nPlease wait 6 minutes.\n If still not working, contact a nerd." + ) fix_manywallets(manywallets) return manywallets