mirror of
https://github.com/lnbits/lnbits.git
synced 2025-06-28 09:40:59 +02:00
* 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:
parent
28661903b6
commit
034813a1ab
@ -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."
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user