Skip to content

Commit

Permalink
Bug fixed. (#378) (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
ATATC authored Sep 4, 2024
1 parent 20efe55 commit 53abd8d
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions leads/leads.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
T = _TypeVar("T", bound=DataContainer)


class _SuspensionException(Exception):
def __init__(self, event: SuspensionEvent) -> None:
super().__init__()
self.event = event


class LEADS(Context[T]):
def __init__(self, initial_data: T | None = None, data_seq_size: int = 100, num_laps_timed: int = 3) -> None:
super().__init__(initial_data, data_seq_size, num_laps_timed)
Expand Down Expand Up @@ -39,15 +45,18 @@ def _acquire_data(self, name: str, key: str, mandatory: bool = True) -> _Any | N
return getattr(self.data(), name)
except AttributeError:
if mandatory:
self.suspend(SuspensionEvent(self, key, f"No data for `{name}`"))
raise _SuspensionException(SuspensionEvent(self, key, f"No data for `{name}`"))

def _do_plugin_callback(self, method: _Literal["pre_push", "post_push", "pre_update", "post_update"]) -> None:
for key, plugin in self._plugins.items():
if plugin.enabled():
for tag in plugin.required_devices():
if not has_device(tag) or not SFT.device_ok(tag):
self.suspend(SuspensionEvent(self, key, f"Device {tag} not ok"))
getattr(plugin, method)(self, {d: self._acquire_data(d, key) for d in plugin.required_data()})
try:
for tag in plugin.required_devices():
if not has_device(tag) or not SFT.device_ok(tag):
raise _SuspensionException(SuspensionEvent(self, key, f"Device {tag} not ok"))
getattr(plugin, method)(self, {d: self._acquire_data(d, key) for d in plugin.required_data()})
except _SuspensionException as e:
self.suspend(e.event)

@_override
def push(self, data: T) -> None:
Expand Down

0 comments on commit 53abd8d

Please sign in to comment.