chore: remove unused env and new create unique task

remove old scheduled tasks approach

update min version

Update __init__.py

Co-authored-by: Vlad Stan <stan.v.vlad@gmail.com>
This commit is contained in:
dni ⚡ 2024-03-22 16:57:22 +01:00
commit 65732f7aa0
No known key found for this signature in database
GPG key ID: 886317704CC4E618
3 changed files with 11 additions and 22 deletions

View file

@ -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)

View file

@ -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"
}

View file

@ -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()