ui+server: schedule next-run / last-run on dashboard + schedules tab

P2R-14. New store.LatestJobBySchedule query (per-schedule fired job).
Schedules-tab handler computes next-fire from cron + last-fire from
the jobs table per row. Schedules table grows two columns; dashboard
host row prepends 'next 12h ago/from now' to the existing last-backup
line when a single covering schedule is the run-now candidate.

Embeds store.Schedule into scheduleRow so existing template field
references keep working without bulk renames.
This commit is contained in:
2026-05-04 10:44:31 +01:00
parent 6589f23313
commit 93ab0ae84f
7 changed files with 201 additions and 4 deletions
+36 -2
View File
@@ -25,10 +25,22 @@ import (
// the template doesn't need to do per-row store lookups.
type hostSchedulesPage struct {
hostChromeData
Schedules []store.Schedule
Schedules []scheduleRow
GroupNames map[string]string
}
// scheduleRow bundles a schedule with its derived "next run" + "last
// run" data. The Schedule is embedded so existing template field
// references (`$sc.ID`, `$sc.CronExpr`, etc) keep working when we
// switch the iterating slice from []store.Schedule to []scheduleRow.
type scheduleRow struct {
store.Schedule
NextRun *time.Time
LastRun *time.Time
LastJobID string
LastStatus string // succeeded|failed|running|queued — empty when never fired
}
// scheduleFormData mirrors the form's wire shape — strings + bool for
// round-trip on validation re-render.
type scheduleFormData struct {
@@ -74,6 +86,28 @@ func (s *Server) handleUISchedulesList(w stdhttp.ResponseWriter, r *stdhttp.Requ
names[g.ID] = g.Name
}
now := time.Now().UTC()
rows := make([]scheduleRow, 0, len(scheds))
for _, sc := range scheds {
row := scheduleRow{Schedule: sc}
if sc.Enabled {
if sched, err := cronParser.Parse(sc.CronExpr); err == nil {
next := sched.Next(now).UTC()
row.NextRun = &next
}
}
if j, jerr := s.deps.Store.LatestJobBySchedule(r.Context(), host.ID, sc.ID); jerr == nil && j != nil {
t := j.CreatedAt
if j.StartedAt != nil {
t = *j.StartedAt
}
row.LastRun = &t
row.LastJobID = j.ID
row.LastStatus = j.Status
}
rows = append(rows, row)
}
chrome := s.loadHostChrome(r, *host, "schedules", "schedules")
chrome.ScheduleCount = len(scheds)
chrome.SourceGroupCount = len(groups)
@@ -82,7 +116,7 @@ func (s *Server) handleUISchedulesList(w stdhttp.ResponseWriter, r *stdhttp.Requ
view.Title = host.Name + " schedules · restic-manager"
view.Page = hostSchedulesPage{
hostChromeData: chrome,
Schedules: scheds,
Schedules: rows,
GroupNames: names,
}
if err := s.deps.UI.Render(w, "host_schedules", view); err != nil {