Change flag name, fix output waiting

This commit is contained in:
Ilia Babanov 2024-09-19 10:52:42 +02:00
parent 843f377271
commit 75b2bcbea9
No known key found for this signature in database
GPG Key ID: 17E5E4BD05551A6D
3 changed files with 22 additions and 19 deletions

View File

@ -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
}

View File

@ -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())
}

View File

@ -53,7 +53,7 @@ type Sync struct {
// Synchronization progress events are sent to this event notifier.
notifier EventNotifier
notifierWg *stdsync.WaitGroup
outputWaitGroup *stdsync.WaitGroup
seq int
}
@ -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 {
@ -135,7 +135,7 @@ func New(ctx context.Context, opts SyncOptions) (*Sync, error) {
snapshot: snapshot,
filer: filer,
notifier: notifier,
notifierWg: notifierWg,
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) {