From 772ae2a1abf7626412cd2b6b3f86915e8b88cfe2 Mon Sep 17 00:00:00 2001 From: jackstar12 <62219658+jackstar12@users.noreply.github.com> Date: Thu, 3 Aug 2023 09:53:36 +0200 Subject: [PATCH] support uvicorn reload functionality (#1841) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * support uvicorn reload functionality see: https://github.com/encode/uvicorn/blob/8239373ec649b1a41179070b6ba2c8dc549df63e/uvicorn/main.py#L580-L582 * add docs for --reload --------- Co-authored-by: dni ⚡ --- Makefile | 3 +++ docs/devs/development.md | 15 +++++++++++++++ lnbits/server.py | 10 +++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 944f98979..3ae284cef 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,9 @@ checkblack: checkisort: poetry run isort --check-only . +dev: + poetry run lnbits --reload + test: LNBITS_BACKEND_WALLET_CLASS="FakeWallet" \ FAKE_WALLET_SECRET="ToTheMoon1" \ diff --git a/docs/devs/development.md b/docs/devs/development.md index e64ad2017..6d5984224 100644 --- a/docs/devs/development.md +++ b/docs/devs/development.md @@ -12,6 +12,21 @@ For developers Thanks for contributing :) +Run +===== + +This starts the lnbits uvicorn server +```bash +poetry run lnbits +``` + +This starts the lnbits uvicorn with hot reloading. +```bash +make dev +# or +poetry run lnbits --reload +``` + Precommit hooks ===== diff --git a/lnbits/server.py b/lnbits/server.py index 9b6c05849..787ddc5e4 100644 --- a/lnbits/server.py +++ b/lnbits/server.py @@ -1,4 +1,5 @@ import uvloop +from uvicorn.supervisors import ChangeReload uvloop.install() @@ -73,7 +74,14 @@ def main( ) server = uvicorn.Server(config=config) - process = mp.Process(target=server.run) + + if config.should_reload: + sock = config.bind_socket() + run = ChangeReload(config, target=server.run, sockets=[sock]).run + else: + run = server.run + + process = mp.Process(target=run) process.start() server_restart.wait() server_restart.clear()