Setup redis cache (ttags)

This commit is contained in:
phil 2023-12-23 15:08:42 +05:30
parent f47e018e65
commit 5c9d82f507
6 changed files with 82 additions and 62 deletions

View file

@ -1,36 +1,24 @@
from contextlib import asynccontextmanager
import logging
from typing import Any
#import colorama
#colorama.init()
from contextlib import asynccontextmanager
from fastapi import FastAPI, responses
from .api import api
from .geoapi import api as geoapi
from .config import conf
from .registry import registry, ModelRegistry
from .redis_tools import setup_redis, shutdown_redis, setup_redis_cache
from .registry import registry
from .redis_tools import setup_redis, setup_redis_cache, shutdown_redis
from .live import setup_live
logging.basicConfig(level=conf.gisaf.debugLevel)
logger = logging.getLogger(__name__)
## Subclass FastAPI to add attributes to be used globally, ie. registry
class GisafExtra:
registry: ModelRegistry
#raw_survey_models: dict[str, Any] = {}
#survey_models: dict[str, Any] = {}
class GisafFastAPI(FastAPI):
gisaf_extra: GisafExtra
@asynccontextmanager
async def lifespan(app: FastAPI):
await registry.make_registry()
await setup_redis()
await setup_redis_cache()
await setup_live()
yield
await shutdown_redis()