diff --git a/__init__.py b/__init__.py index d1310c2..a78367f 100644 --- a/__init__.py +++ b/__init__.py @@ -1,13 +1,11 @@ import asyncio from typing import List -from environs import Env from fastapi import APIRouter -from loguru import logger from lnbits.db import Database from lnbits.helpers import template_renderer -from lnbits.tasks import catch_everything_and_restart +from lnbits.tasks import create_permanent_unique_task db = Database("ext_lnurlp") @@ -26,22 +24,25 @@ lnurlp_redirect_paths = [ } ] -scheduled_tasks: List[asyncio.Task] = [] lnurlp_ext: APIRouter = APIRouter(prefix="/lnurlp", tags=["lnurlp"]) - def lnurlp_renderer(): return template_renderer(["lnurlp/templates"]) - from .lnurl import * # noqa: F401,F403 from .tasks import wait_for_paid_invoices from .views import * # noqa: F401,F403 from .views_api import * # noqa: F401,F403 +scheduled_tasks: List[asyncio.Task] = [] + + +def lnurlp_stop(): + for task in scheduled_tasks: + task.cancel() + def lnurlp_start(): - loop = asyncio.get_event_loop() - task = loop.create_task(catch_everything_and_restart(wait_for_paid_invoices)) + task = create_permanent_unique_task("lnurlp", wait_for_paid_invoices) scheduled_tasks.append(task) diff --git a/config.json b/config.json index 77c14f9..b8edf91 100644 --- a/config.json +++ b/config.json @@ -3,5 +3,5 @@ "short_description": "Make reusable LNURL pay links", "tile": "/lnurlp/static/image/lnurl-pay.png", "contributors": ["arcbtc", "eillarra", "fiatjaf", "callebtc"], - "min_lnbits_version": "0.11.2" + "min_lnbits_version": "0.12.4" } diff --git a/views_api.py b/views_api.py index fd16853..80a522c 100644 --- a/views_api.py +++ b/views_api.py @@ -1,5 +1,4 @@ import json -from asyncio.log import logger from http import HTTPStatus from fastapi import Depends, Query, Request @@ -10,7 +9,7 @@ from lnbits.core.crud import get_user from lnbits.decorators import WalletTypeInfo, check_admin, get_key_type from lnbits.utils.exchange_rates import currencies, get_fiat_rate_satoshis -from . import lnurlp_ext, scheduled_tasks +from . import lnurlp_ext from .crud import ( create_pay_link, delete_lnurlp_settings, @@ -182,17 +181,6 @@ async def api_check_fiat_rate(currency): return {"rate": rate} -@lnurlp_ext.delete("/api/v1", dependencies=[Depends(check_admin)]) -async def api_stop(): - for t in scheduled_tasks: - try: - t.cancel() - except Exception as ex: - logger.warning(ex) - - return {"success": True} - - @lnurlp_ext.get("/api/v1/settings", dependencies=[Depends(check_admin)]) async def api_get_or_create_settings() -> LnurlpSettings: return await get_or_create_lnurlp_settings()