From 3c9437f801dcacf7aad25a44942cf7a5e58315d1 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Fri, 26 Nov 2021 21:16:47 +1100 Subject: [PATCH] slightly more responsive --- pkg/gui/containers_panel.go | 90 +++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 43 deletions(-) diff --git a/pkg/gui/containers_panel.go b/pkg/gui/containers_panel.go index 25fb6770..8aabc66f 100644 --- a/pkg/gui/containers_panel.go +++ b/pkg/gui/containers_panel.go @@ -178,58 +178,62 @@ func (gui *Gui) renderContainerLogs(container *commands.Container) error { mainView.Wrap = gui.Config.UserConfig.Gui.WrapMainPanel return gui.T.NewTickerTask(time.Millisecond*200, nil, func(stop, notifyStopped chan struct{}) { - gui.clearMainView() + gui.renderContainerLogsAux(container, stop, notifyStopped) + }) +} - command := utils.ApplyTemplate( - gui.Config.UserConfig.CommandTemplates.ContainerLogs, - gui.DockerCommand.NewCommandObject(commands.CommandObject{Container: container}), - ) - cmd := gui.OSCommand.RunCustomCommand(command) +func (gui *Gui) renderContainerLogsAux(container *commands.Container, stop, notifyStopped chan struct{}) { + gui.clearMainView() - // Ensure the child process is treated as a group, as the child process spawns - // its own children. Termination requires sending the signal to the group - // process ID. - gui.OSCommand.PrepareForChildren(cmd) + command := utils.ApplyTemplate( + gui.Config.UserConfig.CommandTemplates.ContainerLogs, + gui.DockerCommand.NewCommandObject(commands.CommandObject{Container: container}), + ) + cmd := gui.OSCommand.RunCustomCommand(command) - mainView := gui.getMainView() - cmd.Stdout = mainView - cmd.Stderr = mainView + // Ensure the child process is treated as a group, as the child process spawns + // its own children. Termination requires sending the signal to the group + // process ID. + gui.OSCommand.PrepareForChildren(cmd) - cmd.Start() + mainView := gui.getMainView() + cmd.Stdout = mainView + cmd.Stderr = mainView - go func() { - <-stop - if err := gui.OSCommand.Kill(cmd); err != nil { - gui.Log.Warn(err) - } - gui.Log.Info("killed container logs process") + cmd.Start() + + go func() { + <-stop + if err := gui.OSCommand.Kill(cmd); err != nil { + gui.Log.Warn(err) + } + gui.Log.Info("killed container logs process") + return + }() + + cmd.Wait() + + // if we are here because the task has been stopped, we should return + // if we are here then the container must have exited, meaning we should wait until it's back again before + ticker := time.NewTicker(time.Millisecond * 100) + defer ticker.Stop() + for { + select { + case <-stop: return - }() - - cmd.Wait() - - // if we are here because the task has been stopped, we should return - // if we are here then the container must have exited, meaning we should wait until it's back again before - L: - for { - select { - case <-stop: + case <-ticker.C: + result, err := container.Inspect() + if err != nil { + // if we get an error, then the container has probably been removed so we'll get out of here + gui.Log.Error(err) + notifyStopped <- struct{}{} + return + } + if result.State.Running { return - default: - result, err := container.Inspect() - if err != nil { - // if we get an error, then the container has probably been removed so we'll get out of here - gui.Log.Error(err) - notifyStopped <- struct{}{} - return - } - if result.State.Running { - break L - } - time.Sleep(time.Millisecond * 100) } } - }) + } } func (gui *Gui) refreshContainersAndServices() error {