- planification crontab par stack (autoupdate.json), incompatible avec l'exclusion
- scheduler a la minute ; pull puis down + up -d seulement si une image a change (mode autoapply)
- API PUT .../targets/{t}/auto et GET /api/cron (apercu des prochaines executions)
- interface : option dans le detail, badge sarcelle, vue de suivi "Mises a jour auto"
- TZ dans docker-compose / .env.example (tzdata embarque)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LNfwm6UCYFyvNQNSF5i9Gy
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package api
|
|
|
|
import (
|
|
"log/slog"
|
|
"net/http"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/vblogio/stackwatch/internal/fleet"
|
|
)
|
|
|
|
// tzName : fuseau dans lequel les planifications sont evaluees.
|
|
func tzName() string {
|
|
if tz := os.Getenv("TZ"); tz != "" {
|
|
return tz
|
|
}
|
|
name, _ := time.Now().Zone()
|
|
return name
|
|
}
|
|
|
|
// autoUpdate programme (schedule) ou desactive (schedule vide) la mise a jour
|
|
// automatique d'une stack.
|
|
func (h *Handler) autoUpdate(w http.ResponseWriter, r *http.Request) {
|
|
if !h.admin(w, r) {
|
|
return
|
|
}
|
|
var req struct {
|
|
Dir string `json:"dir"`
|
|
Schedule string `json:"schedule"`
|
|
}
|
|
if !h.decode(w, r, &req) {
|
|
return
|
|
}
|
|
if err := h.Fleet.SetAuto(r.PathValue("id"), r.PathValue("target"), req.Dir, req.Schedule, UserID(r)); err != nil {
|
|
fail(w, err)
|
|
return
|
|
}
|
|
slog.Info("mise a jour automatique", "server", r.PathValue("id"), "target", r.PathValue("target"), "dir", req.Dir, "schedule", req.Schedule, "by", UserID(r))
|
|
writeJSON(w, http.StatusOK, map[string]string{"schedule": req.Schedule})
|
|
}
|
|
|
|
// cronPreview valide une planification et renvoie ses prochaines executions.
|
|
func (h *Handler) cronPreview(w http.ResponseWriter, r *http.Request) {
|
|
c, err := fleet.ParseCron(r.URL.Query().Get("expr"))
|
|
if err != nil {
|
|
fail(w, err)
|
|
return
|
|
}
|
|
next := []time.Time{}
|
|
t := time.Now()
|
|
for range 3 {
|
|
if t = c.Next(t); t.IsZero() {
|
|
break
|
|
}
|
|
next = append(next, t)
|
|
}
|
|
writeJSON(w, http.StatusOK, map[string]any{"next": next, "tz": tzName()})
|
|
}
|