Merge pull request #534 from docker/interupt

Poll ECS logs until context is canceled
This commit is contained in:
Guillaume Tardif 2020-08-21 16:20:36 +02:00 committed by GitHub
commit d85d963705
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 30 deletions

View File

@ -21,8 +21,6 @@ import (
"context"
"fmt"
"io"
"os"
"os/signal"
"strconv"
"strings"
@ -45,16 +43,9 @@ func (b *ecsAPIService) Logs(ctx context.Context, options *cli.ProjectOptions, w
writer: writer,
}
err := b.SDK.GetLogs(ctx, name, consumer.Log)
if err != nil {
return err
}
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, os.Interrupt)
<-signalChan
return nil
}
func (l *logConsumer) Log(service, container, message string) {
cf, ok := l.colors[service]
if !ok {

View File

@ -436,6 +436,10 @@ func (s sdk) GetLogs(ctx context.Context, name string, consumer func(service, co
logGroup := fmt.Sprintf("/docker-compose/%s", name)
var startTime int64
for {
select {
case <-ctx.Done():
return nil
default:
var hasMore = true
var token *string
for hasMore {
@ -459,6 +463,7 @@ func (s sdk) GetLogs(ctx context.Context, name string, consumer func(service, co
startTime = *event.IngestionTime
}
}
}
time.Sleep(500 * time.Millisecond)
}
}