Skip to content

Commit

Permalink
only update if date is greater than current time
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdudfield committed May 29, 2024
1 parent bcc20e1 commit d05ccc4
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import structlog
from fastapi import APIRouter, Depends, HTTPException, Request
from nowcasting_datamodel.models import ForecastSQL, GSPYieldSQL, Status
from nowcasting_datamodel.read.read import update_latest_input_data_last_updated
from nowcasting_datamodel.read.read import (
get_latest_input_data_last_updated,
update_latest_input_data_last_updated,
)
from sqlalchemy.exc import NoResultFound
from sqlalchemy.orm.session import Session

Expand Down Expand Up @@ -100,9 +103,14 @@ def update_last_data(
fs = fsspec.open(file).fs
modified_date = fs.modified(file)

# update the database
update_latest_input_data_last_updated(
session=session, component=component, update_datetime=modified_date
)
# get last value
latest_input_data = get_latest_input_data_last_updated(session=session)
current_date = getattr(latest_input_data, component)

if current_date < modified_date:
# update the database
update_latest_input_data_last_updated(
session=session, component=component, update_datetime=modified_date
)

return modified_date

0 comments on commit d05ccc4

Please sign in to comment.