refactor: simplify
This commit is contained in:
+7
-1
@@ -37,6 +37,7 @@ from lnbits.core.services.payments import check_pending_payments
|
|||||||
from lnbits.core.tasks import (
|
from lnbits.core.tasks import (
|
||||||
audit_queue,
|
audit_queue,
|
||||||
collect_exchange_rates_data,
|
collect_exchange_rates_data,
|
||||||
|
dispatch_wasm_invoice_paid,
|
||||||
purge_audit_data,
|
purge_audit_data,
|
||||||
run_by_the_minute_tasks,
|
run_by_the_minute_tasks,
|
||||||
wait_for_audit_data,
|
wait_for_audit_data,
|
||||||
@@ -507,7 +508,12 @@ def register_async_tasks(app: FastAPI) -> None:
|
|||||||
# core invoice listener
|
# core invoice listener
|
||||||
invoice_queue: asyncio.Queue = asyncio.Queue()
|
invoice_queue: asyncio.Queue = asyncio.Queue()
|
||||||
register_invoice_listener(invoice_queue, "core")
|
register_invoice_listener(invoice_queue, "core")
|
||||||
create_permanent_task(lambda: wait_for_paid_invoices(invoice_queue, app))
|
|
||||||
|
async def dispatch_extension_invoice_paid(payment) -> None:
|
||||||
|
await dispatch_wasm_invoice_paid(app, payment)
|
||||||
|
|
||||||
|
core_app_extra.dispatch_extension_invoice_paid = dispatch_extension_invoice_paid
|
||||||
|
create_permanent_task(lambda: wait_for_paid_invoices(invoice_queue))
|
||||||
|
|
||||||
create_permanent_task(run_by_the_minute_tasks)
|
create_permanent_task(run_by_the_minute_tasks)
|
||||||
create_permanent_task(purge_audit_data)
|
create_permanent_task(purge_audit_data)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Awaitable, Callable
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
@@ -9,10 +10,17 @@ def _do_nothing(*_):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
async def _do_nothing_async(_: Any) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class CoreAppExtra:
|
class CoreAppExtra:
|
||||||
register_new_ext_routes: Callable = _do_nothing
|
register_new_ext_routes: Callable = _do_nothing
|
||||||
register_new_wasm_ext_routes: Callable = _do_nothing
|
register_new_wasm_ext_routes: Callable = _do_nothing
|
||||||
register_new_ratelimiter: Callable
|
register_new_ratelimiter: Callable
|
||||||
|
dispatch_extension_invoice_paid: Callable[[Any], Awaitable[None]] = (
|
||||||
|
_do_nothing_async
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ConversionData(BaseModel):
|
class ConversionData(BaseModel):
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ from lnbits.core.crud.audit import delete_expired_audit_entries
|
|||||||
from lnbits.core.crud.payments import get_payments_status_count
|
from lnbits.core.crud.payments import get_payments_status_count
|
||||||
from lnbits.core.crud.users import get_accounts
|
from lnbits.core.crud.users import get_accounts
|
||||||
from lnbits.core.crud.wallets import get_wallets_count
|
from lnbits.core.crud.wallets import get_wallets_count
|
||||||
|
from lnbits.core.db import core_app_extra
|
||||||
from lnbits.core.models.audit import AuditEntry
|
from lnbits.core.models.audit import AuditEntry
|
||||||
from lnbits.core.models.extensions import InstallableExtension
|
from lnbits.core.models.extensions import InstallableExtension
|
||||||
from lnbits.core.models.notifications import NotificationType
|
from lnbits.core.models.notifications import NotificationType
|
||||||
@@ -92,9 +93,7 @@ async def _notify_server_status() -> None:
|
|||||||
enqueue_admin_notification(NotificationType.server_status, values)
|
enqueue_admin_notification(NotificationType.server_status, values)
|
||||||
|
|
||||||
|
|
||||||
async def wait_for_paid_invoices(
|
async def wait_for_paid_invoices(invoice_paid_queue: asyncio.Queue) -> None:
|
||||||
invoice_paid_queue: asyncio.Queue, app: FastAPI | None = None
|
|
||||||
) -> None:
|
|
||||||
"""
|
"""
|
||||||
This worker dispatches events to all extensions and dispatches webhooks.
|
This worker dispatches events to all extensions and dispatches webhooks.
|
||||||
"""
|
"""
|
||||||
@@ -105,8 +104,7 @@ async def wait_for_paid_invoices(
|
|||||||
wallet = await get_wallet(payment.wallet_id)
|
wallet = await get_wallet(payment.wallet_id)
|
||||||
if wallet:
|
if wallet:
|
||||||
await send_payment_notification(wallet, payment)
|
await send_payment_notification(wallet, payment)
|
||||||
if app:
|
await core_app_extra.dispatch_extension_invoice_paid(payment)
|
||||||
await dispatch_wasm_invoice_paid(app, payment)
|
|
||||||
|
|
||||||
|
|
||||||
async def dispatch_wasm_invoice_paid(app: FastAPI, payment: Any) -> None:
|
async def dispatch_wasm_invoice_paid(app: FastAPI, payment: Any) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user