fix(archied): report workflow definitions apply status at start and on a timer
This commit is contained in:
4 files changed
+17
-2
No files matched your search
@@ -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
|
||||
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
Reference in new issue
Block a user