fix(mcp): list_maintenance_plans reports only a slot that fired as last_slot_at (#5863)
A new plan's last_slot_at holds the moment it was made, so its first slot is the next one; the tool returned that moment, a Wednesday evening for a Sunday plan, beside latest_run: null. cadence.fired_slot returns it only when it falls on one of the plan's slots. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -55,6 +55,16 @@ def last_slot(plan, now: datetime) -> datetime:
|
||||
return slot.astimezone(timezone.utc)
|
||||
|
||||
|
||||
def fired_slot(plan) -> datetime | None:
|
||||
"""The last slot that fired, or None while none has. A new plan's
|
||||
last_slot_at holds the moment it was made, so its first slot is the
|
||||
next one rather than one already past; that moment is no slot (#5863)."""
|
||||
at = plan.last_slot_at
|
||||
if at is None:
|
||||
return None
|
||||
return at if last_slot(plan, at) == at else None
|
||||
|
||||
|
||||
def next_slot(plan, now: datetime) -> datetime:
|
||||
return last_slot(plan, now) + timedelta(days=7)
|
||||
|
||||
|
||||
@@ -136,7 +136,8 @@ async def list_maintenance_plans() -> dict:
|
||||
|
||||
A run updates the group's hosts one at a time; `latest_run` says how far
|
||||
it got (`hosts_done` of `hosts`), which hosts it passed over and why
|
||||
(`skipped`), and how it ended. get_maintenance_job shows one host's job.
|
||||
(`skipped`), and how it ended. `last_slot_at` is the last scheduled slot
|
||||
that fired, null until one has. get_maintenance_job shows one host's job.
|
||||
Plans are created and edited on the Maintenance page.
|
||||
"""
|
||||
from steward.models.ansible_inventory import AnsibleGroup
|
||||
@@ -164,7 +165,7 @@ async def list_maintenance_plans() -> dict:
|
||||
"weekday": cadence.WEEKDAYS[plan.weekday], "at_time": plan.at_time,
|
||||
"time_zone": plan.time_zone, "window_minutes": plan.window_minutes,
|
||||
"reboot_policy": plan.reboot_policy, "enabled": plan.enabled,
|
||||
"next_slot_at": iso(nxt), "last_slot_at": iso(plan.last_slot_at),
|
||||
"next_slot_at": iso(nxt), "last_slot_at": iso(cadence.fired_slot(plan)),
|
||||
"latest_run": None,
|
||||
}
|
||||
if run:
|
||||
|
||||
Reference in New Issue
Block a user