fix(agent): retry failed node config applies (#40)

This commit is contained in:
Ryan
2026-10-07 10:27:00 +08:00
committed by GitHub
parent 6c15c11e35
commit 2960a4ddeb
4 changed files with 217 additions and 6 deletions
+15 -2
View File
@@ -43,6 +43,7 @@ type Cycle struct {
Sync SyncService
Updater *updater.Service
RecordSyncError func(err error)
ConfigSyncResult func(target *protocol.ActiveConfigMeta, err error)
}
// Perform executes one complete heartbeat cycle: sends the heartbeat, syncs config, and applies settings.
@@ -69,14 +70,16 @@ func (c *Cycle) Perform(ctx context.Context, nodeID string, startup bool, settin
c.ApplyWAFIPGroups(ctx, heartbeatResult.WAFIPGroups)
if startup {
if err = c.Sync.SyncOnStartup(ctx, heartbeatResult.ActiveConfig); err != nil {
c.recordSyncError(err)
slog.Error("agent startup sync failed", "error", err)
} else {
slog.Debug("agent startup sync completed")
}
c.reportConfigSyncResult(heartbeatResult.ActiveConfig, err)
} else if err = c.Sync.SyncOnce(ctx, heartbeatResult.ActiveConfig); err != nil {
c.recordSyncError(err)
slog.Error("agent sync failed", "error", err)
c.reportConfigSyncResult(heartbeatResult.ActiveConfig, err)
} else {
c.reportConfigSyncResult(heartbeatResult.ActiveConfig, nil)
}
if settings != nil {
settings.RestartOpenrestyIfNeeded(ctx)
@@ -85,6 +88,16 @@ func (c *Cycle) Perform(ctx context.Context, nodeID string, startup bool, settin
return changed, nil
}
func (c *Cycle) reportConfigSyncResult(target *protocol.ActiveConfigMeta, err error) {
if c.ConfigSyncResult != nil {
c.ConfigSyncResult(target, err)
return
}
if err != nil {
c.recordSyncError(err)
}
}
// NodePayload builds and returns the full NodePayload to be sent in a heartbeat request.
func (c *Cycle) NodePayload(ctx context.Context, nodeID string) protocol.NodePayload {
snapshot, _ := c.StateStore.Load()