fix: do not wait for events that have already arrived

This commit is contained in:
lucasheld 2023-04-07 20:07:52 +02:00
parent 307b25249c
commit be537a14d2

View file

@ -451,8 +451,9 @@ class UptimeKumaApi(object):
@contextmanager @contextmanager
def wait_for_event(self, event: Event) -> None: def wait_for_event(self, event: Event) -> None:
# 200 * 0.05 seconds = 10 seconds
retries = 200 retries = 200
event_data_before = deepcopy(self._event_data) sleep = 0.05
try: try:
yield yield
@ -460,11 +461,11 @@ class UptimeKumaApi(object):
raise raise
else: else:
counter = 0 counter = 0
while event_data_before[event] == self._event_data[event]: while self._event_data[event] is None:
time.sleep(0.01) time.sleep(sleep)
counter += 1 counter += 1
if counter >= retries: if counter >= retries:
print("wait_for_event timeout") print(f"wait_for_event {event} timeout")
break break
def _get_event_data(self, event) -> Any: def _get_event_data(self, event) -> Any: