Skip to content

Commit

Permalink
fix: add error if fail to get interval block url for usage point
Browse files Browse the repository at this point in the history
  • Loading branch information
JPHutchins committed Feb 6, 2022
1 parent 4b083cc commit ba09e02
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
5 changes: 5 additions & 0 deletions open_energy_view/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Define errors."""


class OEVErrorIntervalBlockURLNotFound(Exception):
pass
17 changes: 14 additions & 3 deletions open_energy_view/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from celery import chain
from celery.result import AsyncResult

from . import errors
from . import models
from . import bcrypt
from . import db
Expand Down Expand Up @@ -367,6 +368,7 @@ def get(self):
user_info = json.loads(user_info)

task_ids = []
failed_usage_points = []

for usage_point, entry in names.items():
if entry["kind"] != "electricity":
Expand All @@ -384,10 +386,17 @@ def get(self):
usage_point=usage_point,
published_period_start=user_info.get("published_period_start"),
)

try:
task_ids.append(
pge_api.get_historical_data_incrementally(new_source).id
)
except errors.OEVErrorIntervalBlockURLNotFound:
failed_usage_points.append(usage_point)
continue

new_source.save_to_db()
task_ids.append(
pge_api.get_historical_data_incrementally(new_source).id
)

except exc.IntegrityError:
db.session.rollback()
source = (
Expand All @@ -408,6 +417,8 @@ def get(self):
task_ids.append(pge_api.get_historical_data_incrementally(source).id)

if len(task_ids) == 0:
if len(failed_usage_points > 0):
return {"error": f"Could not retrieve usage points: {failed_usage_points}"}, 500
return {"message": "No electrical service submitted."}, 200
return (
task_ids[0],
Expand Down
3 changes: 2 additions & 1 deletion open_energy_view/utility_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from gevent import sleep


from . import errors
from . import models
from . import db
from .espi_helpers import save_espi_xml
Expand Down Expand Up @@ -459,7 +460,7 @@ def get_historical_data_incrementally(self, source):
else:
print("Could not find interval block url")
save_espi_xml(response_text, filename=f"SubRespForSource{source.id}")
return {"error": "could not find interval block url"}, 500
raise errors.OEVErrorIntervalBlockURLNotFound

published_period_start = source.published_period_start

Expand Down

0 comments on commit ba09e02

Please sign in to comment.