Skip to content

Commit

Permalink
update message to show error or success
Browse files Browse the repository at this point in the history
  • Loading branch information
nullfunc committed Jun 25, 2024
1 parent d56cde4 commit 7ce4a2b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/cmd/cli/command/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import (
const DEFANG_PORTAL_HOST = "portal.defang.dev"
const SERVICE_PORTAL_URL = "https://" + DEFANG_PORTAL_HOST + "/service"

var ErrorFailedToReachRunningState = errors.New("Failed to reached running state")
var ErrorDeploymentFailed = errors.New("Failed to reached running state")

const authNeeded = "auth-needed" // annotation to indicate that a command needs authorization
var authNeededAnnotation = map[string]string{authNeeded: ""}

Expand Down Expand Up @@ -828,6 +831,7 @@ var composeUpCmd = &cobra.Command{

tailCtx, cancelTail := context.WithCancel(ctx)

deploymentFailed := false
var wg sync.WaitGroup
wg.Add(1)
go func() {
Expand All @@ -841,14 +845,20 @@ var composeUpCmd = &cobra.Command{
}
}()
if err := waitServiceStatus(ctx, cli.ServiceStarted, serviceInfos); err != nil && !errors.Is(err, context.Canceled) {
if !errors.Is(err, cli.ErrDryRun) && !errors.As(err, new(cliClient.ErrNotImplemented)) {
if errors.Is(err, ErrorDeploymentFailed) {
term.Warn("Deployment FAILED. Service(s) not running.")
deploymentFailed = true
} else {
term.Warnf("failed to wait for service status: %v", err)
}
}
cancelTail()
wg.Wait() // Wait for tail to finish

printEndpoints(serviceInfos)
if !deploymentFailed {
printEndpoints(serviceInfos)
}

term.Info("Done.")
return nil
},
Expand Down
8 changes: 6 additions & 2 deletions src/cmd/cli/command/servicemonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package command

import (
"context"
"fmt"

"github.com/DefangLabs/defang/src/pkg/cli"
"github.com/DefangLabs/defang/src/pkg/term"
Expand Down Expand Up @@ -34,6 +33,11 @@ func waitServiceStatus(ctx context.Context, targetStatus cli.ServiceStatus, serv
continue
}

// exit on detecting a FAILED state
if newStatus.Status == string(cli.ServiceFailed) {
return ErrorDeploymentFailed
}

serviceStatus[newStatus.Name] = newStatus.Status

if allInStatus(targetStatus, serviceStatus) {
Expand All @@ -44,7 +48,7 @@ func waitServiceStatus(ctx context.Context, targetStatus cli.ServiceStatus, serv
}
}

return fmt.Errorf("service state monitoring terminated without all services reaching desired state: %s", targetStatus)
return ErrorFailedToReachRunningState
}

func allInStatus(targetStatus cli.ServiceStatus, serviceStatuses map[string]string) bool {
Expand Down

0 comments on commit 7ce4a2b

Please sign in to comment.