Skip to content

Commit 42ee6b3

Browse files
Add resync on system clock time changes to resampler
Signed-off-by: Matthias Wende <matthias.wende@frequenz.com>
1 parent 6f8ed74 commit 42ee6b3

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

‎src/frequenz/sdk/timeseries/_resampling.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,14 @@ async def resample(self, *, one_shot: bool = False) -> None:
503503
async for drift in self._timer:
504504
now = datetime.now(tz=timezone.utc)
505505

506+
# If the system time changes, then `self._window_end` might drift to
507+
# far away, such that the resampling bucket might be empty although
508+
# new samples aligned to the new system time have been received.
509+
# Thus we resync `self._window_end` to the new system time in case
510+
# it drifted more then one resampling period away from the system time.
511+
if abs(self._window_end - now) - drift > self._config.resampling_period:
512+
self._window_end = self._sync_timer(extra_period=False)
513+
506514
if drift > tolerance:
507515
_logger.warning(
508516
"The resampling task woke up too late. Resampling should have "

0 commit comments

Comments
 (0)