stop doing the check_invoices thing on each call. do it once on lnbits starup and then rely on the invoices listener.

This commit is contained in:
fiatjaf
2021-03-21 17:57:33 -03:00
parent f27c2ebc21
commit 7e4a42e7ff
8 changed files with 61 additions and 70 deletions
+14 -9
View File
@@ -4,7 +4,7 @@ from typing import Optional, List, Callable
from quart_trio import QuartTrio
from lnbits.settings import WALLET
from lnbits.core.crud import get_standalone_payment
from lnbits.core.crud import get_payments, get_standalone_payment, delete_expired_invoices
main_app: Optional[QuartTrio] = None
@@ -54,16 +54,21 @@ async def webhook_handler():
internal_invoice_paid, internal_invoice_received = trio.open_memory_channel(0)
async def internal_invoice_listener():
async with trio.open_nursery() as nursery:
async for checking_id in internal_invoice_received:
nursery.start_soon(invoice_callback_dispatcher, checking_id)
async def internal_invoice_listener(nursery):
async for checking_id in internal_invoice_received:
nursery.start_soon(invoice_callback_dispatcher, checking_id)
async def invoice_listener():
async with trio.open_nursery() as nursery:
async for checking_id in WALLET.paid_invoices_stream():
nursery.start_soon(invoice_callback_dispatcher, checking_id)
async def invoice_listener(nursery):
async for checking_id in WALLET.paid_invoices_stream():
nursery.start_soon(invoice_callback_dispatcher, checking_id)
async def check_pending_payments():
await delete_expired_invoices()
for payment in await get_payments(complete=False, pending=True, exclude_uncheckable=True):
print(" - checking pending", payment.checking_id)
await payment.check_pending()
async def invoice_callback_dispatcher(checking_id: str):