migrate to trio so c-lightning sockets stop hanging.
This commit is contained in:
+12
-11
@@ -1,7 +1,8 @@
|
||||
import asyncio
|
||||
import trio # type: ignore
|
||||
import importlib
|
||||
|
||||
from quart import Quart, g
|
||||
from quart import g
|
||||
from quart_trio import QuartTrio
|
||||
from quart_cors import cors # type: ignore
|
||||
from quart_compress import Compress # type: ignore
|
||||
from secure import SecureHeaders # type: ignore
|
||||
@@ -15,11 +16,11 @@ from .proxy_fix import ASGIProxyFix
|
||||
secure_headers = SecureHeaders(hsts=False)
|
||||
|
||||
|
||||
def create_app(config_object="lnbits.settings") -> Quart:
|
||||
def create_app(config_object="lnbits.settings") -> QuartTrio:
|
||||
"""Create application factory.
|
||||
:param config_object: The configuration object to use.
|
||||
"""
|
||||
app = Quart(__name__, static_folder="static")
|
||||
app = QuartTrio(__name__, static_folder="static")
|
||||
app.config.from_object(config_object)
|
||||
app.asgi_http_class = ASGIProxyFix
|
||||
|
||||
@@ -36,7 +37,7 @@ def create_app(config_object="lnbits.settings") -> Quart:
|
||||
return app
|
||||
|
||||
|
||||
def register_blueprints(app: Quart) -> None:
|
||||
def register_blueprints(app: QuartTrio) -> None:
|
||||
"""Register Flask blueprints / LNbits extensions."""
|
||||
app.register_blueprint(core_app)
|
||||
|
||||
@@ -58,13 +59,13 @@ def register_blueprints(app: Quart) -> None:
|
||||
raise ImportError(f"Please make sure that the extension `{ext.code}` follows conventions.")
|
||||
|
||||
|
||||
def register_commands(app: Quart):
|
||||
def register_commands(app: QuartTrio):
|
||||
"""Register Click commands."""
|
||||
app.cli.add_command(db_migrate)
|
||||
app.cli.add_command(handle_assets)
|
||||
|
||||
|
||||
def register_assets(app: Quart):
|
||||
def register_assets(app: QuartTrio):
|
||||
"""Serve each vendored asset separately or a bundle."""
|
||||
|
||||
@app.before_request
|
||||
@@ -77,13 +78,13 @@ def register_assets(app: Quart):
|
||||
g.VENDORED_CSS = ["/static/bundle.css"]
|
||||
|
||||
|
||||
def register_filters(app: Quart):
|
||||
def register_filters(app: QuartTrio):
|
||||
"""Jinja filters."""
|
||||
app.jinja_env.globals["SITE_TITLE"] = app.config["LNBITS_SITE_TITLE"]
|
||||
app.jinja_env.globals["EXTENSIONS"] = get_valid_extensions()
|
||||
|
||||
|
||||
def register_request_hooks(app: Quart):
|
||||
def register_request_hooks(app: QuartTrio):
|
||||
"""Open the core db for each request so everything happens in a big transaction"""
|
||||
|
||||
@app.before_request
|
||||
@@ -109,8 +110,8 @@ def register_async_tasks(app):
|
||||
|
||||
@app.before_serving
|
||||
async def listeners():
|
||||
loop = asyncio.get_running_loop()
|
||||
loop.create_task(invoice_listener())
|
||||
app.nursery.start_soon(invoice_listener)
|
||||
print("started invoice_listener")
|
||||
|
||||
@app.after_serving
|
||||
async def stop_listeners():
|
||||
|
||||
Reference in New Issue
Block a user