feat: add endpoint to stop background tasks
This commit is contained in:
parent
6a5afe3025
commit
6540cd9d76
2 changed files with 18 additions and 3 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from typing import List
|
||||||
|
|
||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
|
@ -16,6 +17,7 @@ lnurlp_static_files = [
|
||||||
"name": "lnurlp_static",
|
"name": "lnurlp_static",
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
scheduled_tasks: List[asyncio.Task] = []
|
||||||
|
|
||||||
lnurlp_ext: APIRouter = APIRouter(prefix="/lnurlp", tags=["lnurlp"])
|
lnurlp_ext: APIRouter = APIRouter(prefix="/lnurlp", tags=["lnurlp"])
|
||||||
|
|
||||||
|
|
@ -32,4 +34,5 @@ from .views_api import * # noqa: F401,F403
|
||||||
|
|
||||||
def lnurlp_start():
|
def lnurlp_start():
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
loop.create_task(catch_everything_and_restart(wait_for_paid_invoices))
|
task = loop.create_task(catch_everything_and_restart(wait_for_paid_invoices))
|
||||||
|
scheduled_tasks.append(task)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import json
|
import json
|
||||||
|
from asyncio.log import logger
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
|
|
||||||
from fastapi import Depends, Query, Request
|
from fastapi import Depends, Query, Request
|
||||||
|
|
@ -6,10 +7,10 @@ from lnurl.exceptions import InvalidUrl as LnurlInvalidUrl
|
||||||
from starlette.exceptions import HTTPException
|
from starlette.exceptions import HTTPException
|
||||||
|
|
||||||
from lnbits.core.crud import get_user
|
from lnbits.core.crud import get_user
|
||||||
from lnbits.decorators import WalletTypeInfo, get_key_type
|
from lnbits.decorators import WalletTypeInfo, check_admin, get_key_type
|
||||||
from lnbits.utils.exchange_rates import currencies, get_fiat_rate_satoshis
|
from lnbits.utils.exchange_rates import currencies, get_fiat_rate_satoshis
|
||||||
|
|
||||||
from . import lnurlp_ext
|
from . import lnurlp_ext, scheduled_tasks
|
||||||
from .crud import (
|
from .crud import (
|
||||||
create_pay_link,
|
create_pay_link,
|
||||||
delete_pay_link,
|
delete_pay_link,
|
||||||
|
|
@ -166,3 +167,14 @@ async def api_check_fiat_rate(currency):
|
||||||
rate = None
|
rate = None
|
||||||
|
|
||||||
return {"rate": rate}
|
return {"rate": rate}
|
||||||
|
|
||||||
|
|
||||||
|
@lnurlp_ext.delete("/api/v1", status_code=HTTPStatus.OK)
|
||||||
|
async def api_stop(wallet: WalletTypeInfo = Depends(check_admin)):
|
||||||
|
for t in scheduled_tasks:
|
||||||
|
try:
|
||||||
|
t.cancel()
|
||||||
|
except Exception as ex:
|
||||||
|
logger.warning(ex)
|
||||||
|
|
||||||
|
return {"success": True}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue