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) return diag.FromErr(err)
} }
sync.Close()
log.Infof(ctx, "Uploaded bundle files") log.Infof(ctx, "Uploaded bundle files")
return nil return nil
} }

View File

@ -26,14 +26,15 @@ func newDeployCommand() *cobra.Command {
var failOnActiveRuns bool var failOnActiveRuns bool
var computeID string var computeID string
var autoApprove bool var autoApprove bool
var showSyncProgress bool var verbose bool
cmd.Flags().BoolVar(&force, "force", false, "Force-override Git branch validation.") 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(&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().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().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(&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().BoolVar(&verbose, "verbose", false, "Enable verbose output.")
cmd.Flags().MarkHidden("sync-progress") // 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 { cmd.RunE = func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context() ctx := cmd.Context()
@ -56,7 +57,7 @@ func newDeployCommand() *cobra.Command {
}) })
var outputHandler sync.OutputHandler var outputHandler sync.OutputHandler
if showSyncProgress { if verbose {
outputHandler = func(ctx context.Context, c <-chan sync.Event) { outputHandler = func(ctx context.Context, c <-chan sync.Event) {
sync.TextOutput(ctx, c, cmd.OutOrStdout()) sync.TextOutput(ctx, c, cmd.OutOrStdout())
} }

View File

@ -52,9 +52,9 @@ type Sync struct {
filer filer.Filer filer filer.Filer
// Synchronization progress events are sent to this event notifier. // Synchronization progress events are sent to this event notifier.
notifier EventNotifier notifier EventNotifier
notifierWg *stdsync.WaitGroup outputWaitGroup *stdsync.WaitGroup
seq int seq int
} }
// New initializes and returns a new [Sync] instance. // 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 notifier EventNotifier
var notifierWg = &stdsync.WaitGroup{} var outputWaitGroup = &stdsync.WaitGroup{}
if opts.OutputHandler != nil { if opts.OutputHandler != nil {
ch := make(chan Event, MaxRequestsInFlight) ch := make(chan Event, MaxRequestsInFlight)
notifier = &ChannelNotifier{ch} notifier = &ChannelNotifier{ch}
notifierWg.Add(1) outputWaitGroup.Add(1)
go func() { go func() {
defer notifierWg.Done() defer outputWaitGroup.Done()
opts.OutputHandler(ctx, ch) opts.OutputHandler(ctx, ch)
}() }()
} else { } else {
@ -129,14 +129,14 @@ func New(ctx context.Context, opts SyncOptions) (*Sync, error) {
return &Sync{ return &Sync{
SyncOptions: &opts, SyncOptions: &opts,
fileSet: fileSet, fileSet: fileSet,
includeFileSet: includeFileSet, includeFileSet: includeFileSet,
excludeFileSet: excludeFileSet, excludeFileSet: excludeFileSet,
snapshot: snapshot, snapshot: snapshot,
filer: filer, filer: filer,
notifier: notifier, notifier: notifier,
notifierWg: notifierWg, outputWaitGroup: outputWaitGroup,
seq: 0, seq: 0,
}, nil }, nil
} }
@ -147,12 +147,12 @@ func (s *Sync) Events() <-chan Event {
} }
func (s *Sync) Close() { func (s *Sync) Close() {
s.notifierWg.Wait()
if s.notifier == nil { if s.notifier == nil {
return return
} }
s.notifier.Close() s.notifier.Close()
s.notifier = nil s.notifier = nil
s.outputWaitGroup.Wait()
} }
func (s *Sync) notifyStart(ctx context.Context, d diff) { func (s *Sync) notifyStart(ctx context.Context, d diff) {