Skip to content

Commit 621dc78

Browse files
edwardrfedw-defang
andauthored
Wait for task finish if we are following a single task (#653)
Subscribe would not work for cd remote commands as the task is running in the cloudformation cd cluster instead of the service cluster, which the ecs events will not be routed to cloudwatch logs where subscribe is following. Co-authored-by: Edward J <[email protected]>
1 parent be30ddf commit 621dc78

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/pkg/cli/client/byoc/aws/byoc.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"sort"
1414
"strings"
1515
"sync"
16+
"time"
1617

1718
"github.com/DefangLabs/defang/src/pkg"
1819
"github.com/DefangLabs/defang/src/pkg/cli/client"
@@ -471,8 +472,17 @@ func (b *ByocAws) Follow(ctx context.Context, req *defangv1.TailRequest) (client
471472
// Assume "etag" is a task ID
472473
eventStream, err = b.driver.TailTaskID(ctx, etag)
473474
taskArn, _ = b.driver.GetTaskArn(etag)
474-
term.Debug("Tailing task", etag)
475+
term.Debugf("Tailing task %s", *taskArn)
475476
etag = "" // no need to filter by etag
477+
478+
var cancel context.CancelCauseFunc
479+
ctx, cancel = context.WithCancelCause(ctx)
480+
go func() {
481+
if err := ecs.WaitForTask(ctx, taskArn, 3*time.Second); err != nil {
482+
time.Sleep(time.Second) // make sure we got all the logs from the task before cancelling
483+
cancel(err)
484+
}
485+
}()
476486
} else {
477487
// Tail CD, kaniko, and all services (this requires ProjectName to be set)
478488
kanikoTail := ecs.LogGroupInput{LogGroupARN: b.driver.MakeARN("logs", "log-group:"+b.stackDir("builds"))} // must match logic in ecs/common.ts

0 commit comments

Comments
 (0)