Skip to content

Commit

Permalink
udpate
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdudfield committed May 29, 2024
1 parent d05ccc4 commit 7958847
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,15 @@ def update_last_data(

# 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 = True
if latest_input_data is not None:
if hasattr(latest_input_data, component):
current_date = getattr(latest_input_data, component)
if current_date >= modified_date:
update = False

if update:
# update the database
update_latest_input_data_last_updated(
session=session, component=component, update_datetime=modified_date
Expand Down
6 changes: 6 additions & 0 deletions src/tests/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ def test_check_last_forecast_gsp(db_session):
assert len(data) == 1
assert data[0].gsp.isoformat() == datetime(2023, 1, 3, tzinfo=timezone.utc).isoformat()

# check no updates is made, as file modified datetime is the same
response = client.get("/v0/solar/GB/update_last_data?component=gsp")
assert response.status_code == 200, response.text
data = db_session.query(InputDataLastUpdatedSQL).all()
assert len(data) == 1


def test_check_last_forecast_file(db_session):
"""Check check_last_forecast_run works fine"""
Expand Down

0 comments on commit 7958847

Please sign in to comment.