mirror of
https://github.com/lnbits/lnbits.git
synced 2025-06-27 17:23:12 +02:00
Retry backend connection on startup
This commit is contained in:
parent
41a9689014
commit
fbafe2b8f1
@ -84,18 +84,20 @@ 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():
|
||||||
error_message, balance = await WALLET.status()
|
success = False
|
||||||
if error_message:
|
while not success:
|
||||||
|
error_message, balance = await WALLET.status()
|
||||||
|
if not error_message:
|
||||||
|
break
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
f" × The backend for {WALLET.__class__.__name__} isn't working properly: '{error_message}'",
|
f" × The backend for {WALLET.__class__.__name__} isn't working properly: '{error_message}'",
|
||||||
RuntimeWarning,
|
RuntimeWarning,
|
||||||
)
|
)
|
||||||
|
print("Retrying connection to backend in 5 seconds...")
|
||||||
sys.exit(4)
|
await asyncio.sleep(5)
|
||||||
else:
|
print(
|
||||||
print(
|
f" ✔️ {WALLET.__class__.__name__} seems to be connected and with a balance of {balance} msat."
|
||||||
f" ✔️ {WALLET.__class__.__name__} seems to be connected and with a balance of {balance} msat."
|
)
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def register_routes(app: FastAPI) -> None:
|
def register_routes(app: FastAPI) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user