support uvicorn reload functionality (#1841)

* support uvicorn reload functionality
see:
8239373ec6/uvicorn/main.py (L580-L582)
* add docs for --reload

---------

Co-authored-by: dni  <office@dnilabs.com>
This commit is contained in:
jackstar12 2023-08-03 09:53:36 +02:00 committed by GitHub
parent 2577ce7f81
commit 772ae2a1ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 1 deletions

View file

@ -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" \

View file

@ -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
=====

View file

@ -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()