fix: temporary unversion SSE channel

The SEE channel currently doesn't work with fastapi-versioned.
This commit is contained in:
Stefan Stammberger 2021-09-07 19:52:57 +02:00
parent c673394fa8
commit 2fd3381521
No known key found for this signature in database
GPG key ID: 645FA807E935D9D5

26
main.py
View file

@ -17,8 +17,8 @@ from app.repositories.bitcoin import (
register_bitcoin_status_gatherer,
register_bitcoin_zmq_sub,
)
from app.repositories.system import register_hardware_info_gatherer
from app.repositories.lightning import register_lightning_listener
from app.repositories.system import register_hardware_info_gatherer
from app.routers import apps, bitcoin, lightning, setup, system
from app.sse_starlette import EventSourceResponse
@ -40,8 +40,16 @@ app.include_router(system.router)
app.include_router(setup.router)
connections = []
app = VersionedFastAPI(
app, version_format="{major}", prefix_format="/v{major}", enable_latest=True
)
@app.on_event("startup")
async def on_startup() -> None:
async def on_startup():
await redis_plugin.init_app(app, config=config)
await redis_plugin.init()
await register_all_handlers()
@ -52,7 +60,10 @@ async def on_shutdown() -> None:
await redis_plugin.terminate()
connections = []
@app.get("/")
def index():
# path operation function
return {"data": "123"}
@app.get("/sse/subscribe", status_code=status.HTTP_200_OK)
@ -63,15 +74,6 @@ async def stream(
return EventSourceResponse(subscribe(request, channel, redis))
app = VersionedFastAPI(app, version_format="{major}", prefix_format="/v{major}")
@app.get("/")
def index():
# path operation function
return {"data": "123"}
async def subscribe(request: Request, channel: str, redis: Redis):
(sub,) = await redis.subscribe(channel=Channel(channel, False))
try: