stuck in retrying backend loop, fix issue #652 (#862)

* maybe solution to issue #652

* formatting, when precommit merge?

* Update lnbits/app.py

* Update lnbits/app.py

Co-authored-by: dni <dni.khr@gmail.com>
Co-authored-by: calle <93376500+callebtc@users.noreply.github.com>
This commit is contained in:
dni ⚡ 2022-08-13 14:46:47 +02:00 committed by GitHub
parent 28661903b6
commit 034813a1ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
import asyncio import asyncio
import importlib import importlib
import logging import logging
import signal
import sys import sys
import traceback import traceback
import warnings import warnings
@ -101,16 +102,27 @@ def create_app(config_object="lnbits.settings") -> FastAPI:
def check_funding_source(app: FastAPI) -> None: def check_funding_source(app: FastAPI) -> None:
@app.on_event("startup") @app.on_event("startup")
async def check_wallet_status(): async def check_wallet_status():
original_sigint_handler = signal.getsignal(signal.SIGINT)
def signal_handler(signal, frame):
logger.debug(f"SIGINT received, terminating LNbits.")
sys.exit(1)
signal.signal(signal.SIGINT, signal_handler)
while True: while True:
error_message, balance = await WALLET.status() try:
if not error_message: error_message, balance = await WALLET.status()
break if not error_message:
logger.error( break
f"The backend for {WALLET.__class__.__name__} isn't working properly: '{error_message}'", logger.error(
RuntimeWarning, f"The backend for {WALLET.__class__.__name__} isn't working properly: '{error_message}'",
) RuntimeWarning,
logger.info("Retrying connection to backend in 5 seconds...") )
await asyncio.sleep(5) logger.info("Retrying connection to backend in 5 seconds...")
await asyncio.sleep(5)
except:
pass
signal.signal(signal.SIGINT, original_sigint_handler)
logger.info( logger.info(
f"✔️ Backend {WALLET.__class__.__name__} connected and with a balance of {balance} msat." f"✔️ Backend {WALLET.__class__.__name__} connected and with a balance of {balance} msat."
) )