mirror of
https://github.com/lnbits/lnbits.git
synced 2025-09-26 20:06:17 +02:00
Startup optimization: nonblocking expiry check (#1943)
* nonblocking expiry check * autoruff * smaller interval --------- Co-authored-by: dni ⚡ <office@dnilabs.com>
This commit is contained in:
@@ -18,7 +18,6 @@ from lnbits.core.crud import (
|
|||||||
get_payments,
|
get_payments,
|
||||||
get_standalone_payment,
|
get_standalone_payment,
|
||||||
)
|
)
|
||||||
from lnbits.core.db import db
|
|
||||||
from lnbits.core.services import redeem_lnurl_withdraw
|
from lnbits.core.services import redeem_lnurl_withdraw
|
||||||
from lnbits.settings import settings
|
from lnbits.settings import settings
|
||||||
from lnbits.wallets import get_wallet_class
|
from lnbits.wallets import get_wallet_class
|
||||||
@@ -149,7 +148,6 @@ async def check_pending_payments():
|
|||||||
incoming = True
|
incoming = True
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
async with db.connect() as conn:
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Task: checking all pending payments (incoming={incoming},"
|
f"Task: checking all pending payments (incoming={incoming},"
|
||||||
f" outgoing={outgoing}) of last 15 days"
|
f" outgoing={outgoing}) of last 15 days"
|
||||||
@@ -162,10 +160,10 @@ async def check_pending_payments():
|
|||||||
outgoing=outgoing,
|
outgoing=outgoing,
|
||||||
incoming=incoming,
|
incoming=incoming,
|
||||||
exclude_uncheckable=True,
|
exclude_uncheckable=True,
|
||||||
conn=conn,
|
|
||||||
)
|
)
|
||||||
for payment in pending_payments:
|
for payment in pending_payments:
|
||||||
await payment.check_status(conn=conn)
|
await payment.check_status()
|
||||||
|
await asyncio.sleep(0.01) # to avoid complete blocking
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Task: pending check finished for {len(pending_payments)} payments"
|
f"Task: pending check finished for {len(pending_payments)} payments"
|
||||||
@@ -175,7 +173,7 @@ async def check_pending_payments():
|
|||||||
if incoming:
|
if incoming:
|
||||||
logger.debug("Task: deleting all expired invoices")
|
logger.debug("Task: deleting all expired invoices")
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
await delete_expired_invoices(conn=conn)
|
await delete_expired_invoices()
|
||||||
logger.info(
|
logger.info(
|
||||||
"Task: expired invoice deletion finished (took"
|
"Task: expired invoice deletion finished (took"
|
||||||
f" {time.time() - start_time:0.3f} s)"
|
f" {time.time() - start_time:0.3f} s)"
|
||||||
|
Reference in New Issue
Block a user