Skip to content

Commit

Permalink
Remove WaitGroup for logs
Browse files Browse the repository at this point in the history
  • Loading branch information
sestrella committed Dec 19, 2024
1 parent 1f210c1 commit c662692
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"log"
"sync"
"time"

"github.com/aws/aws-sdk-go-v2/config"
Expand Down Expand Up @@ -85,29 +84,21 @@ func runLogs(ctx context.Context, ecsClient *ecs.Client, cwlogsClient *cloudwatc
return err
}
stream := startLiveTail.GetStream()
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
eventsChannel := stream.Events()
for {
event := <-eventsChannel
switch e := event.(type) {
case *cloudwatchlogsTypes.StartLiveTailResponseStreamMemberSessionStart:
log.Println("Received SessionStart event")
case *cloudwatchlogsTypes.StartLiveTailResponseStreamMemberSessionUpdate:
for _, logEvent := range e.Value.SessionResults {
date := time.UnixMilli(*logEvent.Timestamp)
fmt.Printf("%v %s\n", date, *logEvent.Message)
}
default:
fmt.Println("TODO")
return
eventsChannel := stream.Events()
for {
event := <-eventsChannel
switch e := event.(type) {
case *cloudwatchlogsTypes.StartLiveTailResponseStreamMemberSessionStart:
log.Println("Received SessionStart event")
case *cloudwatchlogsTypes.StartLiveTailResponseStreamMemberSessionUpdate:
for _, logEvent := range e.Value.SessionResults {
date := time.UnixMilli(*logEvent.Timestamp)
fmt.Printf("%v %s\n", date, *logEvent.Message)
}
default:
log.Fatalf("Unknown event type: %s", e)
}
}()
wg.Wait()
return nil
}
}

func init() {
Expand Down

0 comments on commit c662692

Please sign in to comment.