lnbits-legend/lnbits/extensions/jukebox/tasks.py

25 lines
666 B
Python
Raw Normal View History

2021-10-10 23:57:15 +01:00
import asyncio
2021-10-10 16:23:39 +01:00
2021-10-10 23:57:15 +01:00
from lnbits.core.models import Payment
from lnbits.helpers import get_current_extension_name
2021-10-10 23:57:15 +01:00
from lnbits.tasks import register_invoice_listener
2021-10-10 16:23:39 +01:00
from .crud import update_jukebox_payment
2021-10-10 16:23:39 +01:00
2021-10-10 23:57:15 +01:00
async def wait_for_paid_invoices():
invoice_queue = asyncio.Queue()
register_invoice_listener(invoice_queue, get_current_extension_name())
2021-10-10 16:23:39 +01:00
2021-10-10 23:57:15 +01:00
while True:
payment = await invoice_queue.get()
2021-10-10 16:23:39 +01:00
await on_invoice_paid(payment)
async def on_invoice_paid(payment: Payment) -> None:
if payment.extra.get("tag") != "jukebox":
# not a jukebox invoice
return
await update_jukebox_payment(payment.payment_hash, paid=True)