diff --git a/internal/app/archied/bootstrap.go b/internal/app/archied/bootstrap.go index d542630d1..f41cae050 100644 --- a/internal/app/archied/bootstrap.go +++ b/internal/app/archied/bootstrap.go @@ -67,9 +67,10 @@ import ( // reverse at shutdown, matching the LIFO ordering of the deferred calls // they replace. type boot struct { - catalog *modelcatalog.Catalog - cfg config.Config - log *slog.Logger + catalog *modelcatalog.Catalog + cfg config.Config + log *slog.Logger + playbooks *controlplane.LivePlaybooks // stderrLog keeps setupLogging on stderr, never touching cfg.Log.File. An // offline command reads the bootstrap config but is not the daemon: creating @@ -864,7 +865,9 @@ func (b *boot) startModelCatalogRefresh(ctx context.Context) { } func (b *boot) livePlaybooks() *controlplane.LivePlaybooks { - live := controlplane.NewLivePlaybooks(b.controlPlaneRPC, b.log) - live.ApplyStatus = b.applyStatus - return live + b.playbooks = controlplane.NewLivePlaybooks(b.controlPlaneRPC, b.log) + b.playbooks.ApplyStatus = b.applyStatus + return b.playbooks } + +const playbookRefreshInterval = 30 * time.Second diff --git a/internal/app/archied/main.go b/internal/app/archied/main.go index 102ab7481..4395a383c 100644 --- a/internal/app/archied/main.go +++ b/internal/app/archied/main.go @@ -207,6 +207,7 @@ func Run() int { //nolint:cyclop,funlen // the composition root's setup sequence } b.buildDaemon() + b.playbooks.Keep(ctx, playbookRefreshInterval) b.wireConfigSurfaces(ctx, args.cfgPath, args.overlayPath) if err := b.startServices(ctx); err != nil { diff --git a/internal/app/controlplane/playbooks_client.go b/internal/app/controlplane/playbooks_client.go index 6bff2be80..c68ac474a 100644 --- a/internal/app/controlplane/playbooks_client.go +++ b/internal/app/controlplane/playbooks_client.go @@ -41,6 +41,24 @@ func NewLivePlaybooks(client pb.ControlPlaneServiceClient, log *slog.Logger) *Li return &LivePlaybooks{rpc: client, log: log, orgs: map[org.OrgID]*orgPlaybooks{}} } +// Keep loads the default org's playbooks now and every interval after, so the +// apply status is reported without waiting for the first dispatch. +func (l *LivePlaybooks) Keep(ctx context.Context, interval time.Duration) { + l.current(ctx) + go func() { + ticker := time.NewTicker(interval) + defer ticker.Stop() + for { + select { + case <-ctx.Done(): + return + case <-ticker.C: + l.current(ctx) + } + } + }() +} + // current reads the playbooks of the org ctx acts in; the query carries that // org, so a task is matched against its own org's document. func (l *LivePlaybooks) current(ctx context.Context) *playbook.Store {