mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
handle errors when streaming logs
This commit is contained in:
@@ -251,7 +251,12 @@ func (l *LogsCommand) Run(args []string) int {
|
||||
}
|
||||
|
||||
defer r.Close()
|
||||
io.Copy(os.Stdout, r)
|
||||
_, err = io.Copy(os.Stdout, r)
|
||||
if err != nil {
|
||||
l.Ui.Error(fmt.Sprintf("error following logs: %s", err))
|
||||
return 1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -261,16 +266,18 @@ func (l *LogsCommand) followFile(client *api.Client, alloc *api.Allocation,
|
||||
follow bool, task, logType, origin string, offset int64) (io.ReadCloser, error) {
|
||||
|
||||
cancel := make(chan struct{})
|
||||
frames, err := client.AllocFS().Logs(alloc, follow, task, logType, origin, offset, cancel, nil)
|
||||
if err != nil {
|
||||
frames, errCh := client.AllocFS().Logs(alloc, follow, task, logType, origin, offset, cancel, nil)
|
||||
select {
|
||||
case err := <-errCh:
|
||||
return nil, err
|
||||
default:
|
||||
}
|
||||
signalCh := make(chan os.Signal, 1)
|
||||
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)
|
||||
|
||||
// Create a reader
|
||||
var r io.ReadCloser
|
||||
frameReader := api.NewFrameReader(frames, cancel)
|
||||
frameReader := api.NewFrameReader(frames, errCh, cancel)
|
||||
frameReader.SetUnblockTime(500 * time.Millisecond)
|
||||
r = frameReader
|
||||
|
||||
|
||||
Reference in New Issue
Block a user