feat(master): POLL_INTERVAL, poller wiring and version picker in the UI (#9)

This commit is contained in:
2026-10-13 08:14:43 +02:00
parent c6ea2d3710
commit 2390b6151e
10 changed files with 438 additions and 11 deletions
+47
View File
@@ -5,7 +5,9 @@ import (
"time"
"github.com/shcizo/package-updater/internal/imageref"
"github.com/shcizo/package-updater/internal/master/jobs"
"github.com/shcizo/package-updater/internal/master/model"
"github.com/shcizo/package-updater/internal/master/poller"
"github.com/shcizo/package-updater/internal/protocol"
)
@@ -54,6 +56,51 @@ func shortRef(ref string) string {
return r.String()
}
// followsNoTag says the service's image reference has a digest but no tag,
// so there is no tag to poll or update.
func followsNoTag(svc model.Service) bool {
return jobs.FollowedRef(svc.ActualRef) == ""
}
// versionRow is an image version as shown on the service page.
type versionRow struct {
model.ImageVersion
Running bool // the service runs exactly this digest
}
// versionRows marks the version the service runs now, by digest.
func versionRows(versions []model.ImageVersion, actualDigest string) []versionRow {
rows := make([]versionRow, len(versions))
for i, v := range versions {
rows[i] = versionRow{ImageVersion: v, Running: v.Digest != "" && v.Digest == actualDigest}
}
return rows
}
// pollingStatus is the text of the "Polling" row on the service page and
// whether it is a registry error.
func pollingStatus(svc model.Service, interval time.Duration) (text string, failed bool) {
switch {
case poller.SkipReason(svc) != "":
return "not polled: " + poller.SkipReason(svc), false
case svc.LastPollError != "":
return "last check failed: " + svc.LastPollError, true
}
return "every " + shortDuration(interval), false
}
// shortDuration formats d without trailing zero units: "6h", "1h30m", "90s".
func shortDuration(d time.Duration) string {
s := d.String()
if strings.HasSuffix(s, "m0s") {
s = s[:len(s)-2]
}
if strings.HasSuffix(s, "h0m") {
s = s[:len(s)-2]
}
return s
}
type agentRow struct {
model.Agent
Online bool