feat: improve codequality and CI (#25)

* feat: improve codequality and CI
This commit is contained in:
dni ⚡ 2024-08-30 13:20:23 +02:00 committed by GitHub
parent 28121184c3
commit cc6752003a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 3114 additions and 292 deletions

View file

@ -3,16 +3,16 @@ import asyncio
from fastapi import APIRouter
from loguru import logger
from lnbits.db import Database
from lnbits.helpers import template_renderer
from lnbits.tasks import create_permanent_unique_task
from .relay.client_manager import NostrClientManager
db = Database("ext_nostrrelay")
from .client_manager import client_manager
from .crud import db
from .tasks import wait_for_paid_invoices
from .views import nostrrelay_generic_router
from .views_api import nostrrelay_api_router
nostrrelay_ext: APIRouter = APIRouter(prefix="/nostrrelay", tags=["NostrRelay"])
nostrrelay_ext.include_router(nostrrelay_generic_router)
nostrrelay_ext.include_router(nostrrelay_api_router)
client_manager: NostrClientManager = NostrClientManager()
nostrrelay_static_files = [
{
@ -29,30 +29,31 @@ nostrrelay_redirect_paths = [
}
]
def nostrrelay_renderer():
return template_renderer(["nostrrelay/templates"])
from .tasks import wait_for_paid_invoices
from .views import * # noqa
from .views_api import * # noqa
scheduled_tasks: list[asyncio.Task] = []
async def nostrrelay_stop():
def nostrrelay_stop():
for task in scheduled_tasks:
try:
task.cancel()
except Exception as ex:
logger.warning(ex)
try:
await client_manager.stop()
asyncio.run(client_manager.stop())
except Exception as ex:
logger.warning(ex)
def nostrrelay_start():
from lnbits.tasks import create_permanent_unique_task
task = create_permanent_unique_task("ext_nostrrelay", wait_for_paid_invoices)
scheduled_tasks.append(task)
__all__ = [
"db",
"nostrrelay_ext",
"nostrrelay_start",
"nostrrelay_stop",
]