Skip to content

Commit

Permalink
chore: refactor new loop checker, note to do
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaqq committed Oct 10, 2024
1 parent 97c3780 commit 9d0928d
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion juju/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
from ._sync import SyncCacheLine, ThreadedAsyncRunner

if TYPE_CHECKING:
from .client._definitions import ApplicationStatus, FullStatus
from .client._definitions import ApplicationStatus, FullStatus, UnitStatus
from .application import Application
from .machine import Machine
from .relation import Relation
Expand Down Expand Up @@ -3062,11 +3062,58 @@ async def _check_idle(
expected_idle_since = now - timedelta(seconds=idle_period)
full_status = await self.get_status()

# FIXME check this precedence
for app_name in apps:
if not full_status.applications.get(app_name):
logging.info("Waiting for app %r", app_name)
return False

# priority order is this:
#
# Machine error (any unit of any app from apps)
# Agent error (-"-)
# Workload error (-"-)
# App error (any app from apps)
#
# Workload blocked (any unit of any app from apps)
# App blocked (any app from apps)
units: Dict[str, UnitStatus] = {}
for app_name in apps:
#assert full_status.applications[app_name]
app = full_status.applications[app_name]
assert app
for unit_name, unit in app.units.items():
assert unit
units[unit_name] = unit

for unit_name, unit in units.items():
if unit.machine:
...

for unit_name, unit in units.items():
if unit.agent_status.status == "error" and ...:
...

for unit_name, unit in units.items():
if unit.workload_status.status == "errpr" and ...:
...

# add app check

for unit_name, unit in units.items():
if unit.workload_status.status == "blocked" and ...:
...

# add app check


# remove this
for app_name in apps:
if not (app := full_status.applications.get(app_name)):
logging.info("Waiting for app %r", app_name)
return False

# FIXME compound status is not effective
app_status, app_info = self._compound_status(full_status, app_name)
if app_status == "error" and raise_on_error:
raise JujuAppError(f"App {app_name!r} is in error: {app_info!r}")
Expand Down

0 comments on commit 9d0928d

Please sign in to comment.