Skip to content

Commit

Permalink
Updated app init and versions
Browse files Browse the repository at this point in the history
  • Loading branch information
devdupont committed Oct 30, 2023
1 parent 2bcea5e commit 2279a6e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
34 changes: 17 additions & 17 deletions avwx_api/app_config.py
Expand Up @@ -16,7 +16,7 @@

# module
from avwx import exceptions as avwx_exceptions
from avwx_api_core.app import add_cors, CustomJSONEncoder
from avwx_api_core.app import add_cors, CustomJSONProvider
from avwx_api_core.cache import CacheManager
from avwx_api_core.token import TokenManager
from avwx_api.station_counter import StationCounter
Expand All @@ -30,24 +30,10 @@


app = Pint(__name__)
app.json_encoder = CustomJSONEncoder
app.json_provider_class = CustomJSONProvider
app.after_request(add_cors)


@app.before_serving
async def init_helpers():
"""Init API helpers
Need async to connect helpers to event loop
"""
app.mdb = AsyncIOMotorClient(MONGO_URI) if MONGO_URI else None
app.cache = CacheManager(app, expires=CACHE_EXPIRES)
app.token = TokenManager(app)
app.station = StationCounter(app)
app.cache_only = {}


@app.before_first_request
def init_rollbar():
"""Initialize Rollbar exception logging"""
key = environ.get("LOG_KEY")
Expand All @@ -62,11 +48,25 @@ def exception_intercept(exception: Exception, **extra: dict) -> None:
avwx_exceptions.exception_intercept = exception_intercept


@app.before_first_request
async def init_cache_only_map():
"""Fetch cache-only station lists for the duration of the worker"""
if app.mdb is None:
return
for table in ("awos",):
codes = await app.mdb.cache[table].distinct("_id")
app.cache_only.update({code: table for code in codes})


@app.before_serving
async def init_helpers():
"""Init API helpers
Need async to connect helpers to event loop
"""
app.mdb = AsyncIOMotorClient(MONGO_URI) if MONGO_URI else None
app.cache = CacheManager(app, expires=CACHE_EXPIRES)
app.token = TokenManager(app)
app.station = StationCounter(app)
app.cache_only = {}
init_rollbar()
await init_cache_only_map()
4 changes: 2 additions & 2 deletions requirements.txt
@@ -1,6 +1,6 @@
# git+https://github.com/avwx-rest/avwx-api-core@a7fc3c9cba08361ebc0bb0bc8c9e711d310146af
git+https://github.com/avwx-rest/avwx-api-core@e7777ef6101ccb90a1a5ee1041f56ae7d2aeeb54

avwx-engine[all]==1.8.24
avwx-engine[all]==1.8.25
hypercorn~=0.15
python-dotenv~=1.0
rollbar>=0.16
Expand Down

0 comments on commit 2279a6e

Please sign in to comment.