Skip to content

Commit

Permalink
Merge pull request #10 from imubit/add-timeout-retry
Browse files Browse the repository at this point in the history
add a retry after pt.InterpolatedValues or pt.RecordedValues timeout
  • Loading branch information
cloud-rocket authored Nov 29, 2023
2 parents 90e491c + a74dcdb commit d2f8646
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/data_agent_osisoft_pi/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@
# from OSIsoft.AF.Asset import * # noqa: E402
# from OSIsoft.AF.UnitsOfMeasure import * # noqa: E402
from OSIsoft.AF.Data import AFBoundaryType # noqa: E402
from OSIsoft.AF.PI import PIPoint, PIPointType, PIServers # noqa: E402
from OSIsoft.AF.PI import ( # noqa: E402
PIPoint,
PIPointType,
PIServers,
PITimeoutException,
)
from OSIsoft.AF.Time import AFTime, AFTimeRange, AFTimeSpan # noqa: E402

# from System import TimeSpan # noqa: E402
Expand Down Expand Up @@ -389,9 +394,17 @@ def read_tag_values_period(
page_time_range = AFTimeRange(next_start_time, next_end_time)

# https://docs.aveva.com/bundle/af-sdk/page/html/M_OSIsoft_AF_PI_PIPoint_InterpolatedValues.htm
records = pt.InterpolatedValues(
page_time_range, time_span, "", False
)
try:
records = pt.InterpolatedValues(
page_time_range, time_span, "", False
)
except PITimeoutException as e:
log.warn(
f"Retrying after pt.InterpolatedValues timeout: {e}"
)
records = pt.InterpolatedValues(
page_time_range, time_span, "", False
)

if records.Count == 0:
break
Expand Down Expand Up @@ -436,9 +449,15 @@ def read_tag_values_period(
values_to_read = min(self._page_size, total_values_to_read)

# https://docs.aveva.com/bundle/af-sdk/page/html/M_OSIsoft_AF_PI_PIPoint_RecordedValues.htm
records = pt.RecordedValues(
page_time_range, boundary, "", False, values_to_read
)
try:
records = pt.RecordedValues(
page_time_range, boundary, "", False, values_to_read
)
except PITimeoutException as e:
log.warn(f"Retrying after pt.RecordedValues timeout: {e}")
records = pt.RecordedValues(
page_time_range, boundary, "", False, values_to_read
)

if records.Count == 0:
break
Expand Down

0 comments on commit d2f8646

Please sign in to comment.