code quality fixes and cleanup

This commit is contained in:
Riccardo Balbo 2024-09-07 09:09:22 +00:00
commit 2bbbcd4d65
32 changed files with 4943 additions and 1368 deletions

View file

@ -1,18 +1,22 @@
import asyncio
from fastapi import APIRouter
from lnbits.db import Database
from lnbits.helpers import template_renderer
from lnbits.tasks import create_permanent_unique_task
from loguru import logger
from lnbits.tasks import create_permanent_unique_task
from .crud import db
from .tasks import handle_execution_queue, handle_nwc
from .views import nwcprovider_router
from .views_api import nwcprovider_api_router
db = Database("ext_nwcprovider")
execution_queue = asyncio.Queue()
scheduled_tasks: list[asyncio.Task] = []
nwcprovider_ext: APIRouter = APIRouter(
prefix="/nwcprovider", tags=["NWC Service Provider"]
)
nwcprovider_ext.include_router(nwcprovider_router)
nwcprovider_ext.include_router(nwcprovider_api_router)
nwcprovider_static_files = [
{
@ -22,25 +26,6 @@ nwcprovider_static_files = [
]
def nwcprovider_renderer():
return template_renderer(["nwcprovider/templates"])
async def enqueue(action):
future = asyncio.Future()
execution_queue.put_nowait({
"action": action,
"future": future
})
return await future
from .views import *
from .views_api import *
from .tasks import handle_nwc, handle_execution_queue
def nwcprovider_stop():
for task in scheduled_tasks:
try:
@ -53,6 +38,9 @@ def nwcprovider_start():
task = create_permanent_unique_task("ext_nwcprovider", handle_nwc)
scheduled_tasks.append(task)
task = create_permanent_unique_task(
"ext_nwcprovider_execution_queue", handle_execution_queue)
"ext_nwcprovider_execution_queue", handle_execution_queue
)
scheduled_tasks.append(task)
__all__ = ["db"]