diff --git a/openaq_api/openaq_api/main.py b/openaq_api/openaq_api/main.py index 190490d..e523ed6 100644 --- a/openaq_api/openaq_api/main.py +++ b/openaq_api/openaq_api/main.py @@ -51,6 +51,7 @@ locations, manufacturers, measurements, + owners, parameters, providers, sensors, @@ -107,22 +108,6 @@ def render(self, content: Any) -> bytes: redis_client = None # initialize for generalize_schema.py -if settings.RATE_LIMITING: - logger.debug("Connecting to redis") - from redis.asyncio.cluster import RedisCluster - - try: - redis_client = RedisCluster( - host=settings.REDIS_HOST, - port=settings.REDIS_PORT, - decode_responses=True, - socket_timeout=5, - ) - app.state.redis_client = redis_client - except Exception as e: - logging.error(InfrastructureErrorLog(detail=f"failed to connect to redis: {e}")) - logger.debug("Redis connected") - app.add_middleware( CORSMiddleware, @@ -207,7 +192,24 @@ async def startup_event(): logger.debug("initializing connection pool") app.state.pool = await db_pool(None) logger.debug("Connection pool established") - + if not hasattr(app.state, "redis_client"): + if settings.RATE_LIMITING: + logger.debug("Connecting to redis") + from redis.asyncio.cluster import RedisCluster + + try: + redis_client = RedisCluster( + host=settings.REDIS_HOST, + port=settings.REDIS_PORT, + decode_responses=True, + socket_timeout=5, + ) + app.state.redis_client = redis_client + except Exception as e: + logging.error( + InfrastructureErrorLog(detail=f"failed to connect to redis: {e}") + ) + logger.debug("Redis connected") if hasattr(app.state, "counter"): app.state.counter += 1 else: @@ -244,6 +246,7 @@ def pong(): def favico(): return RedirectResponse("https://openaq.org/assets/graphics/meta/favicon.png") + # v3 app.include_router(instruments.router) app.include_router(locations.router) @@ -252,6 +255,7 @@ def favico(): app.include_router(countries.router) app.include_router(manufacturers.router) app.include_router(measurements.router) +app.include_router(owners.router) app.include_router(trends.router) app.include_router(providers.router) app.include_router(sensors.router) diff --git a/openaq_api/openaq_api/v3/models/responses.py b/openaq_api/openaq_api/v3/models/responses.py index 0072784..e28c5cf 100644 --- a/openaq_api/openaq_api/v3/models/responses.py +++ b/openaq_api/openaq_api/v3/models/responses.py @@ -171,7 +171,7 @@ class Provider(ProviderBase): class Owner(OwnerBase): - entity: EntityBase + locations_count: int = Field(alias='locationsCount') class Instrument(InstrumentBase):