(feature) Show next scheduled run and backup run type in the UI
Add a scheduler helper that calculates the next due time for a cron-style schedule expression and surface that value on the dashboard and host detail pages. Show the latest run type in host summaries and backup trend tables so manual and scheduled backups are distinguishable in the Django UI. Keep the calculation derived from existing ScheduleConfig data without adding a migration.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -36,6 +36,17 @@ def is_due(expr: str, moment: datetime) -> bool:
|
||||
)
|
||||
|
||||
|
||||
def next_due_after(expr: str, moment: datetime, *, max_days: int = 366) -> datetime | None:
|
||||
parse_cron_expr(expr)
|
||||
candidate = moment.replace(second=0, microsecond=0) + timedelta(minutes=1)
|
||||
deadline = candidate + timedelta(days=max_days)
|
||||
while candidate <= deadline:
|
||||
if is_due(expr, candidate):
|
||||
return candidate
|
||||
candidate += timedelta(minutes=1)
|
||||
return None
|
||||
|
||||
|
||||
def _field_matches(field: str, value: int, min_value: int, max_value: int, sunday_alias: bool = False) -> bool:
|
||||
for part in field.split(","):
|
||||
if _part_matches(part.strip(), value, min_value, max_value, sunday_alias=sunday_alias):
|
||||
|
||||
Reference in New Issue
Block a user