async def METHOD_NAME():
    """
    check_pending_payments is called during startup to check for pending payments with
    the backend and also to delete expired invoices. Incoming payments will be
    checked only once, outgoing pending payments will be checked regularly.
    """
    outgoing = True
    incoming = True
    while True:
        async with db.connect() as conn:
            logger.info(
                f"Task: checking all pending payments (incoming={incoming},"
                f" outgoing={outgoing}) of last 15 days"
            )
            start_time = time.time()
            pending_payments = await get_payments(
                since=(int(time.time()) - 60 * 60 * 24 * 15),  # 15 days ago
                complete=False,
                pending=True,
                outgoing=outgoing,
                incoming=incoming,
                exclude_uncheckable=True,
                conn=conn,
            )
            for payment in pending_payments:
                await payment.check_status(conn=conn)
            logger.info(
                f"Task: pending check finished for {len(pending_payments)} payments"
                f" (took {time.time() - start_time:0.3f} s)"
            )
            # we delete expired invoices once upon the first pending check
            if incoming:
                logger.debug("Task: deleting all expired invoices")
                start_time = time.time()
                await delete_expired_invoices(conn=conn)
                logger.info(
                    "Task: expired invoice deletion finished (took"
                    f" {time.time() - start_time:0.3f} s)"
                )
        # after the first check we will only check outgoing, not incoming
        # that will be handled by the global invoice listeners, hopefully
        incoming = False
        await asyncio.sleep(60 * 30)  # every 30 minutes