From d19cdfd1d826677e8c311ff850e525e1f77177f4 Mon Sep 17 00:00:00 2001 From: kmochocki <kmochocki@syncad.com> Date: Thu, 6 Feb 2025 13:41:16 +0000 Subject: [PATCH] Add initialization timeout to settings --- beekeepy/beekeepy/_handle/beekeeper.py | 4 +++- beekeepy/beekeepy/_interface/settings.py | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/beekeepy/beekeepy/_handle/beekeeper.py b/beekeepy/beekeepy/_handle/beekeeper.py index 65670025..f57b8a21 100644 --- a/beekeepy/beekeepy/_handle/beekeeper.py +++ b/beekeepy/beekeepy/_handle/beekeeper.py @@ -107,7 +107,9 @@ class BeekeeperCommon(BeekeeperNotificationCallbacks, ABC): def __wait_till_ready(self) -> None: assert self.__notification_event_handler is not None, "Notification event handler hasn't been set" - if not self.__notification_event_handler.http_listening_event.wait(timeout=5): + if not self.__notification_event_handler.http_listening_event.wait( + timeout=self._get_settings().initialization_timeout.total_seconds() + ): raise TimeoutError("Waiting too long for beekeeper to be up and running") def _handle_error(self, error: Error) -> None: diff --git a/beekeepy/beekeepy/_interface/settings.py b/beekeepy/beekeepy/_interface/settings.py index a36b2331..4f9aeee9 100644 --- a/beekeepy/beekeepy/_interface/settings.py +++ b/beekeepy/beekeepy/_interface/settings.py @@ -16,11 +16,13 @@ class Settings(HandleSettings): WORKING_DIRECTORY: ClassVar[str] = "BEEKEEPY_WORKING_DIRECTORY" PROPAGATE_SIGINT: ClassVar[str] = "BEEKEEPY_PROPAGATE_SIGINT" CLOSE_TIMEOUT: ClassVar[str] = "BEEKEEPY_CLOSE_TIMEOUT" + INITIALIZATION_TIMEOUT: ClassVar[str] = "BEEKEEPY_INITIALIZATION_TIMEOUT" class Defaults(HandleSettings.Defaults): WORKING_DIRECTORY: ClassVar[Path] = Path.cwd() PROPAGATE_SIGINT: ClassVar[bool] = True CLOSE_TIMEOUT: ClassVar[timedelta] = timedelta(seconds=10.0) + INITIALIZATION_TIMEOUT: ClassVar[timedelta] = timedelta(seconds=5.0) working_directory: Path | None = None """Path, where beekeeper binary will store all it's data and logs.""" @@ -49,6 +51,11 @@ class Settings(HandleSettings): ) """Affects time handle waits before beekeepy closes.""" + initialization_timeout: timedelta = Defaults.default_factory( + EnvironNames.INITIALIZATION_TIMEOUT, + lambda x: (Settings.Defaults.INITIALIZATION_TIMEOUT if x is None else timedelta(seconds=int(x))), + ) + @property def ensured_working_directory(self) -> Path: """This property should be used to make sure, that path to working dir is returned. -- GitLab