mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-06-05 13:10:41 +02:00
removes timeout_start_sec
I misinterpreted this option as the time to wait before starting the task. This is apparently not what it stands for in systemd.service
This commit is contained in:
parent
f83bc0073b
commit
b9a91e5ee2
@ -35,7 +35,6 @@ class PerInstanceTaskDescriptor(Generic[R]):
|
|||||||
restart_sec: float,
|
restart_sec: float,
|
||||||
start_limit_interval_sec: float | None,
|
start_limit_interval_sec: float | None,
|
||||||
start_limit_burst: int,
|
start_limit_burst: int,
|
||||||
timeout_start_sec: float,
|
|
||||||
exit_on_failure: bool,
|
exit_on_failure: bool,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.__func = func
|
self.__func = func
|
||||||
@ -45,7 +44,6 @@ class PerInstanceTaskDescriptor(Generic[R]):
|
|||||||
self.__restart_sec = restart_sec
|
self.__restart_sec = restart_sec
|
||||||
self.__start_limit_interval_sec = start_limit_interval_sec
|
self.__start_limit_interval_sec = start_limit_interval_sec
|
||||||
self.__start_limit_burst = start_limit_burst
|
self.__start_limit_burst = start_limit_burst
|
||||||
self.__timeout_start_sec = timeout_start_sec
|
|
||||||
self.__exit_on_failure = exit_on_failure
|
self.__exit_on_failure = exit_on_failure
|
||||||
|
|
||||||
def __set_name__(self, owner: type[DataService], name: str) -> None:
|
def __set_name__(self, owner: type[DataService], name: str) -> None:
|
||||||
@ -86,7 +84,6 @@ class PerInstanceTaskDescriptor(Generic[R]):
|
|||||||
restart_sec=self.__restart_sec,
|
restart_sec=self.__restart_sec,
|
||||||
start_limit_interval_sec=self.__start_limit_interval_sec,
|
start_limit_interval_sec=self.__start_limit_interval_sec,
|
||||||
start_limit_burst=self.__start_limit_burst,
|
start_limit_burst=self.__start_limit_burst,
|
||||||
timeout_start_sec=self.__timeout_start_sec,
|
|
||||||
exit_on_failure=self.__exit_on_failure,
|
exit_on_failure=self.__exit_on_failure,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -101,7 +98,6 @@ def task( # noqa: PLR0913
|
|||||||
restart_sec: float = 1.0,
|
restart_sec: float = 1.0,
|
||||||
start_limit_interval_sec: float | None = None,
|
start_limit_interval_sec: float | None = None,
|
||||||
start_limit_burst: int = 3,
|
start_limit_burst: int = 3,
|
||||||
timeout_start_sec: float = 0.0,
|
|
||||||
exit_on_failure: bool = False,
|
exit_on_failure: bool = False,
|
||||||
) -> Callable[
|
) -> Callable[
|
||||||
[
|
[
|
||||||
@ -145,8 +141,6 @@ def task( # noqa: PLR0913
|
|||||||
Configures unit start rate limiting. Tasks which are started more than
|
Configures unit start rate limiting. Tasks which are started more than
|
||||||
`start_limit_burst` times within an `start_limit_interval_sec` time span are
|
`start_limit_burst` times within an `start_limit_interval_sec` time span are
|
||||||
not permitted to start any more. Defaults to 3.
|
not permitted to start any more. Defaults to 3.
|
||||||
timeout_start_sec:
|
|
||||||
Configures the time to wait for start-up. Defaults to 0.0.
|
|
||||||
exit_on_failure:
|
exit_on_failure:
|
||||||
If True, exit the service if the task fails and restart_on_failure is False
|
If True, exit the service if the task fails and restart_on_failure is False
|
||||||
or burst limits are exceeded.
|
or burst limits are exceeded.
|
||||||
@ -194,7 +188,6 @@ def task( # noqa: PLR0913
|
|||||||
restart_sec=restart_sec,
|
restart_sec=restart_sec,
|
||||||
start_limit_interval_sec=start_limit_interval_sec,
|
start_limit_interval_sec=start_limit_interval_sec,
|
||||||
start_limit_burst=start_limit_burst,
|
start_limit_burst=start_limit_burst,
|
||||||
timeout_start_sec=timeout_start_sec,
|
|
||||||
exit_on_failure=exit_on_failure,
|
exit_on_failure=exit_on_failure,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -54,8 +54,6 @@ class Task(pydase.data_service.data_service.DataService, Generic[R]):
|
|||||||
Configures unit start rate limiting. Tasks which are started more than
|
Configures unit start rate limiting. Tasks which are started more than
|
||||||
`start_limit_burst` times within an `start_limit_interval_sec` time span are
|
`start_limit_burst` times within an `start_limit_interval_sec` time span are
|
||||||
not permitted to start any more. Defaults to 3.
|
not permitted to start any more. Defaults to 3.
|
||||||
timeout_start_sec:
|
|
||||||
Configures the time to wait for start-up. Defaults to 0.0.
|
|
||||||
exit_on_failure:
|
exit_on_failure:
|
||||||
If True, exit the service if the task fails and restart_on_failure is False
|
If True, exit the service if the task fails and restart_on_failure is False
|
||||||
or burst limits are exceeded.
|
or burst limits are exceeded.
|
||||||
@ -96,7 +94,6 @@ class Task(pydase.data_service.data_service.DataService, Generic[R]):
|
|||||||
restart_sec: float,
|
restart_sec: float,
|
||||||
start_limit_interval_sec: float | None,
|
start_limit_interval_sec: float | None,
|
||||||
start_limit_burst: int,
|
start_limit_burst: int,
|
||||||
timeout_start_sec: float,
|
|
||||||
exit_on_failure: bool,
|
exit_on_failure: bool,
|
||||||
) -> None:
|
) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@ -105,7 +102,6 @@ class Task(pydase.data_service.data_service.DataService, Generic[R]):
|
|||||||
self._restart_sec = restart_sec
|
self._restart_sec = restart_sec
|
||||||
self._start_limit_interval_sec = start_limit_interval_sec
|
self._start_limit_interval_sec = start_limit_interval_sec
|
||||||
self._start_limit_burst = start_limit_burst
|
self._start_limit_burst = start_limit_burst
|
||||||
self._timeout_start_sec = timeout_start_sec
|
|
||||||
self._exit_on_failure = exit_on_failure
|
self._exit_on_failure = exit_on_failure
|
||||||
self._func_name = func.__name__
|
self._func_name = func.__name__
|
||||||
self._func = func
|
self._func = func
|
||||||
@ -171,8 +167,6 @@ class Task(pydase.data_service.data_service.DataService, Generic[R]):
|
|||||||
attempts = 0
|
attempts = 0
|
||||||
start_time_of_start_limit_interval = None
|
start_time_of_start_limit_interval = None
|
||||||
|
|
||||||
await self._handle_startup_timeout()
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
await self._func()
|
await self._func()
|
||||||
@ -194,11 +188,6 @@ class Task(pydase.data_service.data_service.DataService, Generic[R]):
|
|||||||
await asyncio.sleep(self._restart_sec)
|
await asyncio.sleep(self._restart_sec)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
async def _handle_startup_timeout(self) -> None:
|
|
||||||
"""Wait for the configured startup timeout."""
|
|
||||||
if self._timeout_start_sec:
|
|
||||||
await asyncio.sleep(self._timeout_start_sec)
|
|
||||||
|
|
||||||
def _handle_task_exception(
|
def _handle_task_exception(
|
||||||
self,
|
self,
|
||||||
exception: Exception,
|
exception: Exception,
|
||||||
|
@ -383,25 +383,6 @@ async def test_non_exceeding_start_limit_interval_sec_and_burst(
|
|||||||
assert service_instance.my_task.status == TaskStatus.RUNNING
|
assert service_instance.my_task.status == TaskStatus.RUNNING
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio(scope="function")
|
|
||||||
async def test_timeout_start_sec(caplog: LogCaptureFixture) -> None:
|
|
||||||
class MyService(pydase.DataService):
|
|
||||||
@task(timeout_start_sec=0.2)
|
|
||||||
async def my_task(self) -> None:
|
|
||||||
logger.info("Starting task.")
|
|
||||||
await asyncio.sleep(1)
|
|
||||||
|
|
||||||
service_instance = MyService()
|
|
||||||
state_manager = StateManager(service_instance)
|
|
||||||
DataServiceObserver(state_manager)
|
|
||||||
service_instance.my_task.start()
|
|
||||||
|
|
||||||
await asyncio.sleep(0.1)
|
|
||||||
assert "Starting task." not in caplog.text
|
|
||||||
await asyncio.sleep(0.2)
|
|
||||||
assert "Starting task." in caplog.text
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio(scope="function")
|
@pytest.mark.asyncio(scope="function")
|
||||||
async def test_exit_on_failure(
|
async def test_exit_on_failure(
|
||||||
monkeypatch: pytest.MonkeyPatch, caplog: LogCaptureFixture
|
monkeypatch: pytest.MonkeyPatch, caplog: LogCaptureFixture
|
||||||
|
Loading…
x
Reference in New Issue
Block a user