fix: refresh dashboard update runs live
Container-Image veröffentlichen / container (push) Multi-Arch-Image veröffentlicht und verifiziert
Container-Image veröffentlichen / container (push) Multi-Arch-Image veröffentlicht und verifiziert
This commit is contained in:
1 parent
bb60c06c0e
commit
fc59092030
11 files changed
+241
-29
No files matched your search
+44
-7
@@ -96,6 +96,23 @@ type accessZone struct {
|
||||
ManagedTargetIDs map[int64]bool
|
||||
}
|
||||
|
||||
type schedulerRunResponse struct {
|
||||
ID int64 `json:"id"`
|
||||
StartedAtUnix int64 `json:"started_at_unix"`
|
||||
Status string `json:"status"`
|
||||
Summary string `json:"summary"`
|
||||
}
|
||||
|
||||
type schedulerResponse struct {
|
||||
NextRunUnix int64 `json:"next_run_unix"`
|
||||
Running bool `json:"running"`
|
||||
Enabled bool `json:"enabled"`
|
||||
IPv6Enabled bool `json:"ipv6_enabled"`
|
||||
LastIPv4 string `json:"last_ipv4"`
|
||||
LastIPv6 string `json:"last_ipv6"`
|
||||
RecentRuns *[]schedulerRunResponse `json:"recent_runs,omitempty"`
|
||||
}
|
||||
|
||||
func New(cfg config.Config, database *store.Store, cipher *secure.Cipher, schedule *scheduler.Scheduler, updates *appupdate.Manager, logger *slog.Logger) (*Server, error) {
|
||||
templates, err := loadTemplates()
|
||||
if err != nil {
|
||||
@@ -1488,20 +1505,40 @@ func (s *Server) statusAPI(w http.ResponseWriter, r *http.Request, _ *model.Sess
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Server) schedulerAPI(w http.ResponseWriter, r *http.Request, _ *model.Session) {
|
||||
func (s *Server) schedulerAPI(w http.ResponseWriter, r *http.Request, session *model.Session) {
|
||||
settings, err := s.store.GetSettings(r.Context())
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
response := schedulerResponse{
|
||||
NextRunUnix: unixSeconds(s.scheduler.NextRunAt()),
|
||||
Running: s.scheduler.IsRunning(),
|
||||
Enabled: settings.UpdaterEnabled,
|
||||
IPv6Enabled: settings.IPv6Enabled,
|
||||
LastIPv4: settings.LastIPv4,
|
||||
LastIPv6: settings.LastIPv6,
|
||||
}
|
||||
if session.Role == "admin" && r.URL.Query().Get("runs") == "1" {
|
||||
runs, err := s.store.RecentRuns(r.Context(), 6)
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
recentRuns := make([]schedulerRunResponse, 0, len(runs))
|
||||
for _, run := range runs {
|
||||
recentRuns = append(recentRuns, schedulerRunResponse{
|
||||
ID: run.ID,
|
||||
StartedAtUnix: unixSeconds(run.StartedAt),
|
||||
Status: run.Status,
|
||||
Summary: run.Summary,
|
||||
})
|
||||
}
|
||||
response.RecentRuns = &recentRuns
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.Header().Set("Cache-Control", "no-store")
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||
"next_run_unix": unixSeconds(s.scheduler.NextRunAt()),
|
||||
"running": s.scheduler.IsRunning(),
|
||||
"enabled": settings.UpdaterEnabled,
|
||||
"last_ipv4": settings.LastIPv4,
|
||||
})
|
||||
_ = json.NewEncoder(w).Encode(response)
|
||||
}
|
||||
|
||||
func (s *Server) usersPage(w http.ResponseWriter, r *http.Request, session *model.Session) {
|
||||
|
||||
Reference in new issue
Block a user