Skip to content

Commit

Permalink
Merge pull request #278 from openaq/fix-owners-resource
Browse files Browse the repository at this point in the history
fixed owners resource
  • Loading branch information
russbiggs authored Sep 20, 2023
2 parents 4b88bf9 + e6a1b68 commit 8c6d837
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
38 changes: 21 additions & 17 deletions openaq_api/openaq_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
locations,
manufacturers,
measurements,
owners,
parameters,
providers,
sensors,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion openaq_api/openaq_api/v3/models/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class Provider(ProviderBase):


class Owner(OwnerBase):
entity: EntityBase
locations_count: int = Field(alias='locationsCount')


class Instrument(InstrumentBase):
Expand Down

0 comments on commit 8c6d837

Please sign in to comment.