mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-11-25 15:06:20 +01:00
fix(prediction): update all providers before reporting a failing one
The prediction container stopped at the first enabled provider that failed to update, so the providers after it in the sequence were not updated in that run. A failing weather provider, at the start of the sequence, thus also kept the electricity price, feed-in tariff, load and PV forecasts from being updated. The container now updates all providers and then raises one RuntimeError with the failures of all enabled providers; with one failing provider the message is unchanged. Refs #1571 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Assisted-by: Claude Code (claude-opus-5-5)
This commit is contained in:
committed by
Bobby Noelte
co-authored by
Claude Opus 5.5
parent
867bc38fc0
commit
c8f793c203
@@ -2483,13 +2483,18 @@ class DataContainer(SingletonMixin, DataABC, Generic[DataProviderT]):
|
|||||||
concurrent writes or other bulk operations can interleave with the
|
concurrent writes or other bulk operations can interleave with the
|
||||||
provider updates.
|
provider updates.
|
||||||
|
|
||||||
|
A failing provider does not stop the update: the remaining providers are
|
||||||
|
updated first, then the failures of the enabled providers are raised together.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
force_enable: If True, forces the update even if a provider is disabled.
|
force_enable: If True, forces the update even if a provider is disabled.
|
||||||
force_update: If True, forces providers to update even if data is cached.
|
force_update: If True, forces providers to update even if data is cached.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
RuntimeError: If an enabled provider fails during update.
|
RuntimeError: If one or more enabled providers fail during update, after
|
||||||
|
all providers have been updated.
|
||||||
"""
|
"""
|
||||||
|
errors: list[str] = []
|
||||||
async with self._container_lock:
|
async with self._container_lock:
|
||||||
for provider in self.providers:
|
for provider in self.providers:
|
||||||
try:
|
try:
|
||||||
@@ -2504,13 +2509,16 @@ class DataContainer(SingletonMixin, DataABC, Generic[DataProviderT]):
|
|||||||
f":\n{e}\n{trace}"
|
f":\n{e}\n{trace}"
|
||||||
)
|
)
|
||||||
if provider.enabled():
|
if provider.enabled():
|
||||||
# The active provider failed — this is a real error worth propagating.
|
# The active provider failed — this is a real error worth propagating,
|
||||||
|
# but only after the remaining providers were updated.
|
||||||
logger.error(error)
|
logger.error(error)
|
||||||
raise RuntimeError(error)
|
errors.append(error)
|
||||||
else:
|
else:
|
||||||
# A non-active provider failed (e.g. missing config while force_enable=True).
|
# A non-active provider failed (e.g. missing config while force_enable=True).
|
||||||
# Log as warning and continue so the remaining providers still run.
|
# Log as warning and continue so the remaining providers still run.
|
||||||
logger.warning(error)
|
logger.warning(error)
|
||||||
|
if errors:
|
||||||
|
raise RuntimeError("\n".join(errors))
|
||||||
|
|
||||||
async def key_to_raw_series(
|
async def key_to_raw_series(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -63,6 +63,27 @@ class DerivedDataProvider(DataProvider[DerivedRecord]):
|
|||||||
DerivedDataProvider.provider_updated = True
|
DerivedDataProvider.provider_updated = True
|
||||||
|
|
||||||
|
|
||||||
|
class FailingDataProvider(DataProvider[DerivedRecord]):
|
||||||
|
"""Enabled DataProvider whose update fails, like a remote API answering HTTP 500."""
|
||||||
|
|
||||||
|
records: List[DerivedRecord] = Field(
|
||||||
|
default_factory=list, description="List of DerivedRecord records"
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def record_class(cls) -> Any:
|
||||||
|
return DerivedRecord
|
||||||
|
|
||||||
|
def provider_id(self) -> str:
|
||||||
|
return "FailingDataProvider"
|
||||||
|
|
||||||
|
def enabled(self) -> bool:
|
||||||
|
return True
|
||||||
|
|
||||||
|
async def _update_data(self, force_update: Optional[bool] = False) -> None:
|
||||||
|
raise RuntimeError("500 Server Error")
|
||||||
|
|
||||||
|
|
||||||
class DerivedDataContainer(DataContainer):
|
class DerivedDataContainer(DataContainer):
|
||||||
providers: List[Union[DerivedDataProvider, DataProvider]] = Field(
|
providers: List[Union[DerivedDataProvider, DataProvider]] = Field(
|
||||||
default_factory=list, description="List of data providers"
|
default_factory=list, description="List of data providers"
|
||||||
@@ -260,6 +281,17 @@ class TestDataContainer:
|
|||||||
assert DerivedDataProvider.provider_updated is True
|
assert DerivedDataProvider.provider_updated is True
|
||||||
DerivedDataProvider.provider_enabled = True # restore
|
DerivedDataProvider.provider_enabled = True # restore
|
||||||
|
|
||||||
|
async def test_update_data_failing_provider_does_not_skip_the_others(
|
||||||
|
self, populated
|
||||||
|
) -> None:
|
||||||
|
"""A failing enabled provider is reported after all others were updated (#1571)."""
|
||||||
|
populated.providers.insert(0, FailingDataProvider())
|
||||||
|
DerivedDataProvider.provider_enabled = True
|
||||||
|
DerivedDataProvider.provider_updated = False
|
||||||
|
with pytest.raises(RuntimeError, match="Provider FailingDataProvider fails on update"):
|
||||||
|
await populated.update_data()
|
||||||
|
assert DerivedDataProvider.provider_updated is True
|
||||||
|
|
||||||
# -----------------------------------------------------------------------
|
# -----------------------------------------------------------------------
|
||||||
# save / load
|
# save / load
|
||||||
# -----------------------------------------------------------------------
|
# -----------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user