diff --git a/internal/app/archied/bootstrap.go b/internal/app/archied/bootstrap.go index f41cae050..a0e2ae1e9 100644 --- a/internal/app/archied/bootstrap.go +++ b/internal/app/archied/bootstrap.go @@ -870,4 +870,6 @@ func (b *boot) livePlaybooks() *controlplane.LivePlaybooks { return b.playbooks } +// playbookRefreshInterval is how often archied re-reads the resources it +// would otherwise load only on first use, so their apply status stays reported. const playbookRefreshInterval = 30 * time.Second diff --git a/internal/app/archied/main.go b/internal/app/archied/main.go index 4395a383c..6f9f78b13 100644 --- a/internal/app/archied/main.go +++ b/internal/app/archied/main.go @@ -208,6 +208,7 @@ func Run() int { //nolint:cyclop,funlen // the composition root's setup sequence b.buildDaemon() b.playbooks.Keep(ctx, playbookRefreshInterval) + b.workflowDefinitions.Keep(ctx, playbookRefreshInterval) b.wireConfigSurfaces(ctx, args.cfgPath, args.overlayPath) if err := b.startServices(ctx); err != nil { diff --git a/internal/app/controlplane/client.go b/internal/app/controlplane/client.go index 89184a719..18d63ebfe 100644 --- a/internal/app/controlplane/client.go +++ b/internal/app/controlplane/client.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "io" + "time" "google.golang.org/grpc" @@ -70,6 +71,12 @@ func (c *WorkflowDefinitionsClient) WorkflowDefinitions(ctx context.Context) (wo return definitions, response.Resource.Version, err } +// Keep reads the collection now and every interval after, so the apply status +// is reported without waiting for the first workflow to resolve. +func (c *WorkflowDefinitionsClient) Keep(ctx context.Context, interval time.Duration) { + keepLoading(ctx, interval, func() { _, _, _ = c.WorkflowDefinitions(ctx) }) +} + // ReplaceWorkflowDefinitions replaces the collection, keeping the previous // value in history. func (c *WorkflowDefinitionsClient) ReplaceWorkflowDefinitions(ctx context.Context, definitions workflow.WorkflowDefinitionCollection, expectedVersion int64, actor, source, requestID string) (int64, error) { diff --git a/internal/app/controlplane/playbooks_client.go b/internal/app/controlplane/playbooks_client.go index c68ac474a..992690ff6 100644 --- a/internal/app/controlplane/playbooks_client.go +++ b/internal/app/controlplane/playbooks_client.go @@ -44,7 +44,12 @@ func NewLivePlaybooks(client pb.ControlPlaneServiceClient, log *slog.Logger) *Li // 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) + keepLoading(ctx, interval, func() { l.current(ctx) }) +} + +// keepLoading runs load now and every interval until ctx ends. +func keepLoading(ctx context.Context, interval time.Duration, load func()) { + load() go func() { ticker := time.NewTicker(interval) defer ticker.Stop() @@ -53,7 +58,7 @@ func (l *LivePlaybooks) Keep(ctx context.Context, interval time.Duration) { case <-ctx.Done(): return case <-ticker.C: - l.current(ctx) + load() } } }()