Skip to content

Commit

Permalink
refactor: rename logCtx to streamCtx
Browse files Browse the repository at this point in the history
I will probably use StreamBuild to stream events as well as logs
in the Kubernetes runtime, so let's just add rename this var now
for clarity.
  • Loading branch information
cognifloyd committed Apr 26, 2022
1 parent 737dc49 commit 2f7fc2a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions executor/linux/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,12 +497,12 @@ func (c *client) StreamBuild(ctx context.Context) error {
// create an error group with the parent context
//
// https://pkg.go.dev/golang.org/x/sync/errgroup?tab=doc#WithContext
logs, logCtx := errgroup.WithContext(ctx)
streams, streamCtx := errgroup.WithContext(ctx)

defer func() {
c.Logger.Trace("waiting for stream functions to return")

err := logs.Wait()
err := streams.Wait()
if err != nil {
c.Logger.Errorf("error in a stream request, %v", err)
}
Expand All @@ -513,15 +513,15 @@ func (c *client) StreamBuild(ctx context.Context) error {
for {
select {
case req := <-c.streamRequests:
logs.Go(func() error {
streams.Go(func() error {
// update engine logger with step metadata
//
// https://pkg.go.dev/github.com/sirupsen/logrus?tab=doc#Entry.WithField
logger := c.Logger.WithField(req.Key, req.Container.Name)

logger.Debugf("streaming logs for %s container %s", req.Key, req.Container.ID)
// stream logs from container
err := req.Stream(logCtx, req.Container)
logger.Debugf("streaming %s container %s", req.Key, req.Container.ID)

err := req.Stream(streamCtx, req.Container)
if err != nil {
logger.Error(err)
}
Expand Down
14 changes: 7 additions & 7 deletions executor/local/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,12 @@ func (c *client) StreamBuild(ctx context.Context) error {
// create an error group with the parent context
//
// https://pkg.go.dev/golang.org/x/sync/errgroup?tab=doc#WithContext
logs, logCtx := errgroup.WithContext(ctx)
streams, streamCtx := errgroup.WithContext(ctx)

defer func() {
fmt.Fprintln(os.Stdout, "waiting for stream functions to return")

err := logs.Wait()
err := streams.Wait()
if err != nil {
fmt.Fprintln(os.Stdout, "error in a stream request:", err)
}
Expand All @@ -366,12 +366,12 @@ func (c *client) StreamBuild(ctx context.Context) error {
for {
select {
case req := <-c.streamRequests:
logs.Go(func() error {
fmt.Fprintf(os.Stdout, "streaming logs for %s container %s", req.Key, req.Container.ID)
// stream logs from container
err := req.Stream(logCtx, req.Container)
streams.Go(func() error {
fmt.Fprintf(os.Stdout, "streaming %s container %s", req.Key, req.Container.ID)

err := req.Stream(streamCtx, req.Container)
if err != nil {
fmt.Fprintln(os.Stdout, "error streaming logs:", err)
fmt.Fprintln(os.Stdout, "error streaming:", err)
}

return nil
Expand Down

0 comments on commit 2f7fc2a

Please sign in to comment.