From 75b2bcbea9bf9cf2c2b29adaf41d3e2dbc50a092 Mon Sep 17 00:00:00 2001 From: Ilia Babanov Date: Thu, 19 Sep 2024 10:52:42 +0200 Subject: [PATCH] Change flag name, fix output waiting --- bundle/deploy/files/upload.go | 2 ++ cmd/bundle/deploy.go | 9 +++++---- libs/sync/sync.go | 30 +++++++++++++++--------------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/bundle/deploy/files/upload.go b/bundle/deploy/files/upload.go index 59940ba92..9c9cf778f 100644 --- a/bundle/deploy/files/upload.go +++ b/bundle/deploy/files/upload.go @@ -37,6 +37,8 @@ func (m *upload) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics { return diag.FromErr(err) } + sync.Close() + log.Infof(ctx, "Uploaded bundle files") return nil } diff --git a/cmd/bundle/deploy.go b/cmd/bundle/deploy.go index 081d895d3..492317347 100644 --- a/cmd/bundle/deploy.go +++ b/cmd/bundle/deploy.go @@ -26,14 +26,15 @@ func newDeployCommand() *cobra.Command { var failOnActiveRuns bool var computeID string var autoApprove bool - var showSyncProgress bool + var verbose bool cmd.Flags().BoolVar(&force, "force", false, "Force-override Git branch validation.") cmd.Flags().BoolVar(&forceLock, "force-lock", false, "Force acquisition of deployment lock.") cmd.Flags().BoolVar(&failOnActiveRuns, "fail-on-active-runs", false, "Fail if there are running jobs or pipelines in the deployment.") cmd.Flags().StringVarP(&computeID, "compute-id", "c", "", "Override compute in the deployment with the given compute ID.") cmd.Flags().BoolVar(&autoApprove, "auto-approve", false, "Skip interactive approvals that might be required for deployment.") - cmd.Flags().BoolVar(&showSyncProgress, "sync-progress", false, "Show file synchronisation progress.") - cmd.Flags().MarkHidden("sync-progress") + cmd.Flags().BoolVar(&verbose, "verbose", false, "Enable verbose output.") + // Verbose flag currently only affects file sync output, it's used by the vscode extension + cmd.Flags().MarkHidden("verbose") cmd.RunE = func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() @@ -56,7 +57,7 @@ func newDeployCommand() *cobra.Command { }) var outputHandler sync.OutputHandler - if showSyncProgress { + if verbose { outputHandler = func(ctx context.Context, c <-chan sync.Event) { sync.TextOutput(ctx, c, cmd.OutOrStdout()) } diff --git a/libs/sync/sync.go b/libs/sync/sync.go index d2880f8a9..b61af44a2 100644 --- a/libs/sync/sync.go +++ b/libs/sync/sync.go @@ -52,9 +52,9 @@ type Sync struct { filer filer.Filer // Synchronization progress events are sent to this event notifier. - notifier EventNotifier - notifierWg *stdsync.WaitGroup - seq int + notifier EventNotifier + outputWaitGroup *stdsync.WaitGroup + seq int } // New initializes and returns a new [Sync] instance. @@ -113,13 +113,13 @@ func New(ctx context.Context, opts SyncOptions) (*Sync, error) { } var notifier EventNotifier - var notifierWg = &stdsync.WaitGroup{} + var outputWaitGroup = &stdsync.WaitGroup{} if opts.OutputHandler != nil { ch := make(chan Event, MaxRequestsInFlight) notifier = &ChannelNotifier{ch} - notifierWg.Add(1) + outputWaitGroup.Add(1) go func() { - defer notifierWg.Done() + defer outputWaitGroup.Done() opts.OutputHandler(ctx, ch) }() } else { @@ -129,14 +129,14 @@ func New(ctx context.Context, opts SyncOptions) (*Sync, error) { return &Sync{ SyncOptions: &opts, - fileSet: fileSet, - includeFileSet: includeFileSet, - excludeFileSet: excludeFileSet, - snapshot: snapshot, - filer: filer, - notifier: notifier, - notifierWg: notifierWg, - seq: 0, + fileSet: fileSet, + includeFileSet: includeFileSet, + excludeFileSet: excludeFileSet, + snapshot: snapshot, + filer: filer, + notifier: notifier, + outputWaitGroup: outputWaitGroup, + seq: 0, }, nil } @@ -147,12 +147,12 @@ func (s *Sync) Events() <-chan Event { } func (s *Sync) Close() { - s.notifierWg.Wait() if s.notifier == nil { return } s.notifier.Close() s.notifier = nil + s.outputWaitGroup.Wait() } func (s *Sync) notifyStart(ctx context.Context, d diff) {