|
8 | 8 | import re |
9 | 9 | import stat |
10 | 10 | import tempfile |
| 11 | +import warnings |
11 | 12 | import weakref |
12 | 13 | import zipfile |
13 | 14 | from concurrent.futures import CancelledError |
@@ -2227,7 +2228,8 @@ async def _get_source_api(self, url, controller_name=None): |
2227 | 2228 | return controller |
2228 | 2229 |
|
2229 | 2230 | async def wait_for_idle(self, apps=None, raise_on_error=True, raise_on_blocked=False, |
2230 | | - wait_for_active=False, timeout=10 * 60, idle_period=15, check_freq=0.5): |
| 2231 | + wait_for_active=False, timeout=10 * 60, idle_period=15, check_freq=0.5, |
| 2232 | + wait_for_status=None): |
2231 | 2233 | """Wait for applications in the model to settle into an idle state. |
2232 | 2234 |
|
2233 | 2235 | :param apps (list[str]): Optional list of specific app names to wait on. |
@@ -2259,7 +2261,14 @@ async def wait_for_idle(self, apps=None, raise_on_error=True, raise_on_blocked=F |
2259 | 2261 |
|
2260 | 2262 | :param check_freq (float): How frequently, in seconds, to check the model. |
2261 | 2263 | The default is every half-second. |
| 2264 | +
|
| 2265 | + :param wait_for_status (str): The status to wait for. If None, not waiting. |
| 2266 | + The default is None (not waiting for any status). |
2262 | 2267 | """ |
| 2268 | + if wait_for_active: |
| 2269 | + warnings.warn("wait_for_active is deprecated; use wait_for_status", DeprecationWarning) |
| 2270 | + wait_for_status = "active" |
| 2271 | + |
2263 | 2272 | timeout = timedelta(seconds=timeout) if timeout is not None else None |
2264 | 2273 | idle_period = timedelta(seconds=idle_period) |
2265 | 2274 | start_time = datetime.now() |
@@ -2311,8 +2320,8 @@ def _raise_for_status(entities, status): |
2311 | 2320 | if raise_on_blocked and unit.workload_status == "blocked": |
2312 | 2321 | blocks.setdefault("Unit", []).append(unit.name) |
2313 | 2322 | continue |
2314 | | - waiting_for_active = wait_for_active and unit.workload_status != "active" |
2315 | | - if not waiting_for_active and unit.agent_status == "idle": |
| 2323 | + waiting_for_status = wait_for_status and unit.workload_status != wait_for_status |
| 2324 | + if not waiting_for_status and unit.agent_status == "idle": |
2316 | 2325 | now = datetime.now() |
2317 | 2326 | idle_start = idle_times.setdefault(unit.name, now) |
2318 | 2327 | if now - idle_start < idle_period: |
|
0 commit comments