Skip to content

Commit

Permalink
don't use progress to render restart, which hides logs
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Oct 22, 2024
1 parent 82417bd commit 75b22db
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions pkg/compose/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ func (s *composeService) handleWatchBatch(ctx context.Context, project *types.Pr
pathMappings[i] = batch[i].PathMapping
}

writeWatchSyncMessage(options.LogTo, serviceName, pathMappings)
writeWatchSyncMessage(options.LogTo, serviceName, pathMappings, restartService)

service, err := project.GetService(serviceName)
if err != nil {
Expand All @@ -537,17 +537,28 @@ func (s *composeService) handleWatchBatch(ctx context.Context, project *types.Pr
return err
}
if restartService {
return s.Restart(ctx, project.Name, api.RestartOptions{
err = s.restart(ctx, project.Name, api.RestartOptions{
Services: []string{serviceName},
Project: project,
NoDeps: false,
})
if err != nil {
return err
}
options.LogTo.Log(
api.WatchLogger,
fmt.Sprintf("service %q restarted", serviceName))

}
return nil
}

// writeWatchSyncMessage prints out a message about the sync for the changed paths.
func writeWatchSyncMessage(log api.LogConsumer, serviceName string, pathMappings []sync.PathMapping) {
func writeWatchSyncMessage(log api.LogConsumer, serviceName string, pathMappings []sync.PathMapping, restart bool) {
action := "Syncing"
if restart {
action = "Syncing and restarting"
}
if logrus.IsLevelEnabled(logrus.DebugLevel) {
hostPathsToSync := make([]string, len(pathMappings))
for i := range pathMappings {
Expand All @@ -556,15 +567,16 @@ func writeWatchSyncMessage(log api.LogConsumer, serviceName string, pathMappings
log.Log(
api.WatchLogger,
fmt.Sprintf(
"Syncing %q after changes were detected: %s",
"%s service %q after changes were detected: %s",
action,
serviceName,
strings.Join(hostPathsToSync, ", "),
),
)
} else {
log.Log(
api.WatchLogger,
fmt.Sprintf("Syncing service %q after %d changes were detected", serviceName, len(pathMappings)),
fmt.Sprintf("%s service %q after %d changes were detected", action, serviceName, len(pathMappings)),
)
}
}
Expand Down

0 comments on commit 75b22db

Please sign in to comment.