feat: 添加节点自动更新功能,支持手动触发更新

This commit is contained in:
ryan
2026-03-10 20:32:27 +08:00
parent 83a11ead2b
commit e72d658e2f
18 changed files with 227 additions and 90 deletions
+7 -3
View File
@@ -35,6 +35,7 @@ type Runner struct {
Updater Updater
autoUpdate bool
updateNow bool
updateRepo string
}
@@ -130,16 +131,19 @@ func (r *Runner) applySettings(settings *protocol.AgentSettings) bool {
}
}
r.autoUpdate = settings.AutoUpdate
r.updateRepo = settings.UpdateRepo
r.updateNow = settings.UpdateNow
r.updateRepo = strings.TrimSpace(settings.UpdateRepo)
return changed
}
func (r *Runner) tryAutoUpdate(ctx context.Context) {
if !r.autoUpdate || r.Updater == nil || r.updateRepo == "" {
shouldCheck := r.autoUpdate || r.updateNow
r.updateNow = false
if !shouldCheck || r.Updater == nil || r.updateRepo == "" {
return
}
if err := r.Updater.CheckAndUpdate(ctx, r.updateRepo); err != nil {
log.Printf("agent auto-update check failed: %v", err)
log.Printf("agent update check failed: %v", err)
}
}
@@ -18,6 +18,7 @@ type AgentSettings struct {
SyncInterval int `json:"sync_interval"`
AutoUpdate bool `json:"auto_update"`
UpdateRepo string `json:"update_repo"`
UpdateNow bool `json:"update_now"`
}
type NodePayload struct {