Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: implement model.wait_for_idle(timeout=n)
Browse files Browse the repository at this point in the history
dimaqq committed Dec 3, 2024

Verified

This commit was signed with the committer’s verified signature. The key has expired.
addaleax Anna Henningsen
1 parent c52ec4c commit 0c9cf43
Showing 2 changed files with 7 additions and 11 deletions.
15 changes: 7 additions & 8 deletions juju/model.py
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
import stat
import sys
import tempfile
import time
import warnings
import weakref
import zipfile
@@ -3281,25 +3282,26 @@ async def new_wait_for_idle(
apps = apps or list(self.applications)
idle_times: dict[str, datetime] = {}
units_ready: set[str] = set() # The units that are in the desired state
last_log_time: list[datetime | None] = [None]

start_time = datetime.now()
deadline = None if timeout is None else time.monotonic() + timeout

while True:
if deadline and time.monotonic() > deadline:
raise jasyncio.TimeoutError(
"Timed out waiting for model to become idle"
)

if await self._check_idle(
apps=apps,
raise_on_error=raise_on_error,
raise_on_blocked=raise_on_blocked,
status=status,
wait_for_at_least_units=wait_for_at_least_units,
wait_for_exact_units=wait_for_exact_units,
timeout=timeout,
idle_period=idle_period,
_wait_for_units=_wait_for_units,
idle_times=idle_times,
units_ready=units_ready,
last_log_time=last_log_time,
start_time=start_time,
):
break

@@ -3314,13 +3316,10 @@ async def _check_idle(
status: str | None,
wait_for_at_least_units: int | None,
wait_for_exact_units: int | None,
timeout: float | None,
idle_period: float,
_wait_for_units: int,
idle_times: dict[str, datetime],
units_ready: set[str],
last_log_time: list[datetime | None],
start_time: datetime,
) -> bool:
now = datetime.now()
expected_idle_since = now - timedelta(seconds=idle_period)
3 changes: 0 additions & 3 deletions tests/unit/test_wait_for_idle.py
Original file line number Diff line number Diff line change
@@ -327,13 +327,10 @@ def kwargs() -> dict[str, Any]:
status=None,
wait_for_at_least_units=None,
wait_for_exact_units=None,
timeout=100,
idle_period=0,
_wait_for_units=1,
idle_times={},
units_ready=set(),
last_log_time=[None],
start_time=datetime.now(),
)


0 comments on commit 0c9cf43

Please sign in to comment.