slightly more responsive

This commit is contained in:
Jesse Duffield 2021-11-26 21:16:47 +11:00
parent 9db6eeac9d
commit 3c9437f801

View file

@ -178,58 +178,62 @@ func (gui *Gui) renderContainerLogs(container *commands.Container) error {
mainView.Wrap = gui.Config.UserConfig.Gui.WrapMainPanel mainView.Wrap = gui.Config.UserConfig.Gui.WrapMainPanel
return gui.T.NewTickerTask(time.Millisecond*200, nil, func(stop, notifyStopped chan struct{}) { return gui.T.NewTickerTask(time.Millisecond*200, nil, func(stop, notifyStopped chan struct{}) {
gui.clearMainView() gui.renderContainerLogsAux(container, stop, notifyStopped)
})
}
command := utils.ApplyTemplate( func (gui *Gui) renderContainerLogsAux(container *commands.Container, stop, notifyStopped chan struct{}) {
gui.Config.UserConfig.CommandTemplates.ContainerLogs, gui.clearMainView()
gui.DockerCommand.NewCommandObject(commands.CommandObject{Container: container}),
)
cmd := gui.OSCommand.RunCustomCommand(command)
// Ensure the child process is treated as a group, as the child process spawns command := utils.ApplyTemplate(
// its own children. Termination requires sending the signal to the group gui.Config.UserConfig.CommandTemplates.ContainerLogs,
// process ID. gui.DockerCommand.NewCommandObject(commands.CommandObject{Container: container}),
gui.OSCommand.PrepareForChildren(cmd) )
cmd := gui.OSCommand.RunCustomCommand(command)
mainView := gui.getMainView() // Ensure the child process is treated as a group, as the child process spawns
cmd.Stdout = mainView // its own children. Termination requires sending the signal to the group
cmd.Stderr = mainView // process ID.
gui.OSCommand.PrepareForChildren(cmd)
cmd.Start() mainView := gui.getMainView()
cmd.Stdout = mainView
cmd.Stderr = mainView
go func() { cmd.Start()
<-stop
if err := gui.OSCommand.Kill(cmd); err != nil { go func() {
gui.Log.Warn(err) <-stop
} if err := gui.OSCommand.Kill(cmd); err != nil {
gui.Log.Info("killed container logs process") 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 return
}() case <-ticker.C:
result, err := container.Inspect()
cmd.Wait() if err != nil {
// if we get an error, then the container has probably been removed so we'll get out of here
// if we are here because the task has been stopped, we should return gui.Log.Error(err)
// if we are here then the container must have exited, meaning we should wait until it's back again before notifyStopped <- struct{}{}
L: return
for { }
select { if result.State.Running {
case <-stop:
return 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 { func (gui *Gui) refreshContainersAndServices() error {