Skip to content

Commit

Permalink
Move broker lifetime events to cache lifetime for now
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Dec 11, 2024
1 parent fe5e3a2 commit 677fed0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/lvmapi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from lvmopstools.kubernetes import Kubernetes

from lvmapi import auth, config
from lvmapi.broker import broker, broker_shutdown, broker_startup
from lvmapi.broker import broker
from lvmapi.cache import cache_lifespan
from lvmapi.routers import (
actors,
Expand Down Expand Up @@ -72,8 +72,8 @@ async def get_id_route(request: Request):


# Lifecycle events for the broker.
app.add_event_handler("startup", broker_startup)
app.add_event_handler("shutdown", broker_shutdown)
# app.add_event_handler("startup", broker_startup)
# app.add_event_handler("shutdown", broker_shutdown)

# Integration with FastAPI.
taskiq_fastapi.init(broker, "lvmapi.app:app")
Expand Down
7 changes: 7 additions & 0 deletions src/lvmapi/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from fastapi_cache.decorator import cache
from redis.asyncio.client import Redis

from lvmapi.broker import broker_shutdown, broker_startup


if TYPE_CHECKING:
from fastapi import FastAPI
Expand All @@ -41,8 +43,13 @@ async def cache_lifespan(_: FastAPI) -> AsyncIterator[None]:
prefix="fastapi-cache",
key_builder=valis_cache_key_builder,
)

await broker_startup()

yield

await broker_shutdown()


async def valis_cache_key_builder(
func,
Expand Down

0 comments on commit 677fed0

Please sign in to comment.