chore: adhere to ruff's "N" rules (#2377)

* chore: adhere to ruff's "N" rules

WARN: reinstall failing extensions!

bunch of more consistent variable naming. inspired by this issue.
https://github.com/lnbits/lnbits/issues/2308

* fixup! chore: adhere to ruff's "N" rules
* rename to funding_source
* skip jmeter

---------

Co-authored-by: Pavol Rusnak <pavol@rusnak.io>
This commit is contained in:
dni ⚡
2024-04-15 09:02:21 +02:00
committed by GitHub
co-authored by Pavol Rusnak
parent 055426ab53
commit 6d5ad9e229
28 changed files with 191 additions and 173 deletions
+16 -14
View File
@@ -25,7 +25,7 @@ from starlette.responses import JSONResponse
from lnbits.core.crud import get_dbversions, get_installed_extensions
from lnbits.core.helpers import migrate_extension_database
from lnbits.core.services import websocketUpdater
from lnbits.core.services import websocket_updater
from lnbits.core.tasks import ( # watchdog_task
killswitch_task,
wait_for_paid_invoices,
@@ -37,7 +37,7 @@ from lnbits.tasks import (
register_invoice_listener,
)
from lnbits.utils.cache import cache
from lnbits.wallets import get_wallet_class, set_wallet_class
from lnbits.wallets import get_funding_source, set_funding_source
from .commands import migrate_databases
from .core import init_core_routers
@@ -81,7 +81,7 @@ async def startup(app: FastAPI):
# initialize WALLET
try:
set_wallet_class()
set_funding_source()
except Exception as e:
logger.error(f"Error initializing {settings.lnbits_backend_wallet_class}: {e}")
set_void_wallet_class()
@@ -110,8 +110,8 @@ async def shutdown():
# wait a bit to allow them to finish, so that cleanup can run without problems
await asyncio.sleep(0.1)
WALLET = get_wallet_class()
await WALLET.cleanup()
funding_source = get_funding_source()
await funding_source.cleanup()
@asynccontextmanager
@@ -178,33 +178,35 @@ def create_app() -> FastAPI:
async def check_funding_source() -> None:
WALLET = get_wallet_class()
funding_source = get_funding_source()
max_retries = settings.funding_source_max_retries
retry_counter = 0
while True:
try:
logger.info(f"Connecting to backend {WALLET.__class__.__name__}...")
error_message, balance = await WALLET.status()
logger.info(f"Connecting to backend {funding_source.__class__.__name__}...")
error_message, balance = await funding_source.status()
if not error_message:
retry_counter = 0
logger.success(
f"✔️ Backend {WALLET.__class__.__name__} connected "
f"✔️ Backend {funding_source.__class__.__name__} connected "
f"and with a balance of {balance} msat."
)
break
logger.error(
f"The backend for {WALLET.__class__.__name__} isn't "
f"The backend for {funding_source.__class__.__name__} isn't "
f"working properly: '{error_message}'",
RuntimeWarning,
)
except Exception as e:
logger.error(f"Error connecting to {WALLET.__class__.__name__}: {e}")
logger.error(
f"Error connecting to {funding_source.__class__.__name__}: {e}"
)
if retry_counter >= max_retries:
set_void_wallet_class()
WALLET = get_wallet_class()
funding_source = get_funding_source()
break
retry_counter += 1
@@ -221,7 +223,7 @@ def set_void_wallet_class():
"Fallback to VoidWallet, because the backend for "
f"{settings.lnbits_backend_wallet_class} isn't working properly"
)
set_wallet_class("VoidWallet")
set_funding_source("VoidWallet")
async def check_installed_extensions(app: FastAPI):
@@ -414,7 +416,7 @@ def initialize_server_logger():
async def update_websocket_serverlog():
while True:
msg = await serverlog_queue.get()
await websocketUpdater(super_user_hash, msg)
await websocket_updater(super_user_hash, msg)
create_permanent_task(update_websocket_serverlog)