Skip to content

Commit

Permalink
Add no cache header to morecast -> WF1 requests (#3971)
Browse files Browse the repository at this point in the history
Adds no cache header to morecast -> WF1 requests to eliminate possibility of cached forecasts where we need the most up to date data.
  • Loading branch information
conbrad authored Sep 26, 2024
1 parent dc018d8 commit 5771b27
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions api/app/morecast_v2/forecasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from app.db.crud.morecast_v2 import get_forecasts_in_range
from app.schemas.morecast_v2 import MoreCastForecastOutput, MoreCastForecastInput, StationDailyFromWF1, WF1ForecastRecordType, WF1PostForecast, WeatherIndeterminate, WeatherDeterminate
from app.wildfire_one.schema_parsers import WFWXWeatherStation
from app.wildfire_one.wfwx_api import get_auth_header, get_forecasts_for_stations_by_date_range, get_wfwx_stations_from_station_codes
from app.wildfire_one.wfwx_api import get_forecasts_for_stations_by_date_range, get_no_cache_auth_header, get_wfwx_stations_from_station_codes
from app.fire_behaviour import cffdrs


Expand Down Expand Up @@ -61,7 +61,7 @@ def construct_wf1_forecast(forecast: MoreCastForecastInput, stations: List[WFWXW

async def construct_wf1_forecasts(session: ClientSession, forecast_records: List[MoreCastForecastInput], stations: List[WFWXWeatherStation], username: str) -> List[WF1PostForecast]:
# Fetch existing forecasts from WF1 for the stations and date range in the forecast records
header = await get_auth_header(session)
header = await get_no_cache_auth_header(session)
forecast_dates = [datetime.fromtimestamp(f.for_date / 1000, timezone.utc) for f in forecast_records]
min_forecast_date = min(forecast_dates)
max_forecast_date = max(forecast_dates)
Expand Down
9 changes: 9 additions & 0 deletions api/app/wildfire_one/wfwx_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ async def get_auth_header(session: ClientSession) -> dict:
return header


async def get_no_cache_auth_header(session: ClientSession) -> dict:
"""Get WFWX auth header with explicit no caching"""
# Fetch auth header
header = await get_auth_header(session)
# Add the cache control header
header["Cache-Control"] = "no-cache"
return header


async def get_stations_by_codes(station_codes: List[int]) -> List[WeatherStation]:
"""Get a list of stations by code, from WFWX Fireweather API."""
logger.info("Using WFWX to retrieve stations by code")
Expand Down

0 comments on commit 5771b27

Please sign in to comment.