run watchContainers with a background context

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2021-09-13 14:52:31 +02:00 committed by Nicolas De loof
parent 4441ff5b21
commit f7c360b721
2 changed files with 4 additions and 4 deletions

View File

@ -37,7 +37,7 @@ func (s *composeService) Logs(ctx context.Context, projectName string, consumer
if options.Follow {
eg.Go(func() error {
printer := newLogPrinter(consumer)
return s.watchContainers(ctx, projectName, options.Services, printer.HandleEvent, containers, func(c types.Container) error {
return s.watchContainers(projectName, options.Services, printer.HandleEvent, containers, func(c types.Container) error {
return s.logContainers(ctx, consumer, c, options)
})
})

View File

@ -47,7 +47,7 @@ func (s *composeService) start(ctx context.Context, project *types.Project, opti
}
eg.Go(func() error {
return s.watchContainers(ctx, project.Name, options.AttachTo, listener, attached, func(container moby.Container) error {
return s.watchContainers(project.Name, options.AttachTo, listener, attached, func(container moby.Container) error {
return s.attachContainer(ctx, container, listener, project)
})
})
@ -69,13 +69,13 @@ func (s *composeService) start(ctx context.Context, project *types.Project, opti
type containerWatchFn func(container moby.Container) error
// watchContainers uses engine events to capture container start/die and notify ContainerEventListener
func (s *composeService) watchContainers(ctx context.Context, projectName string, services []string, listener api.ContainerEventListener, containers Containers, onStart containerWatchFn) error {
func (s *composeService) watchContainers(projectName string, services []string, listener api.ContainerEventListener, containers Containers, onStart containerWatchFn) error {
watched := map[string]int{}
for _, c := range containers {
watched[c.ID] = 0
}
ctx, stop := context.WithCancel(ctx)
ctx, stop := context.WithCancel(context.Background())
err := s.Events(ctx, projectName, api.EventsOptions{
Services: services,
Consumer: func(event api.Event) error {